last ...
This commit is contained in:
@@ -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 ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -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
Binary file not shown.
@@ -0,0 +1,303 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
string ToString()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result = "XOHCL(O(" + (string)open + "),H(" + (string)high + "),C(" + (string)close + "),L(" + (string)low + "))";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Model Support and Resistance
|
||||
// for Specific Bar ...
|
||||
struct XOHCLSupRes
|
||||
{
|
||||
//
|
||||
double res[];
|
||||
|
||||
//
|
||||
double sup[];
|
||||
};
|
||||
|
||||
//
|
||||
struct XValueChanged
|
||||
{
|
||||
datetime at;
|
||||
double from;
|
||||
double to;
|
||||
};
|
||||
|
||||
//
|
||||
// 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 tp;
|
||||
|
||||
//
|
||||
double sl;
|
||||
|
||||
//
|
||||
double r2r;
|
||||
|
||||
//
|
||||
double volume;
|
||||
|
||||
//
|
||||
// Support Signals ...
|
||||
XSignal supports[];
|
||||
|
||||
//
|
||||
XOHCLSupRes supportResistances;
|
||||
};
|
||||
//
|
||||
// EXTENSION Methods ...
|
||||
|
||||
//
|
||||
// Clear an Specific Signal Item ...
|
||||
void Clean(XSignal &item)
|
||||
{
|
||||
//
|
||||
Clean(item.providers);
|
||||
|
||||
//
|
||||
Clean(item.supports);
|
||||
|
||||
//
|
||||
Clean(item.supportResistances);
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
void Clean(XOHCLSupRes &item)
|
||||
{
|
||||
Clean(item.sup);
|
||||
Clean(item.res);
|
||||
}
|
||||
|
||||
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 ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,284 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
|
||||
//
|
||||
// TODO: Fix this ...
|
||||
return;
|
||||
|
||||
//
|
||||
// ENTRY ...
|
||||
string entryName = prefix + "_ENTRY_" + (string)lost;
|
||||
|
||||
//
|
||||
DrawTrendLine(
|
||||
chartID,
|
||||
entryName,
|
||||
0,
|
||||
time3,
|
||||
signal.entry,
|
||||
time,
|
||||
signal.entry,
|
||||
entryColor,
|
||||
entryLineStyle,
|
||||
lineWidth);
|
||||
}
|
||||
|
||||
//
|
||||
void DrawSignals(
|
||||
XSignal &signals[], // Signals To Draw
|
||||
bool drawSupportAndResistances = false // Draw Signal Support and Resistance
|
||||
)
|
||||
{
|
||||
//
|
||||
int signalsCount = ArraySize(signals);
|
||||
if (signalsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < signalsCount; i++)
|
||||
{
|
||||
//
|
||||
XSignal iSignal = signals[i];
|
||||
|
||||
//
|
||||
ulong iTicket = MathRand() * 10000;
|
||||
|
||||
//
|
||||
DrawSignal(iTicket, iSignal);
|
||||
|
||||
//
|
||||
// TODO: Remove this ...
|
||||
return;
|
||||
|
||||
//
|
||||
// Check For Draw Support and Resistances ...
|
||||
bool isValidSupRes = ArraySize(iSignal.supportResistances.sup) > 0 || ArraySize(iSignal.supportResistances.res) > 0;
|
||||
if (drawSupportAndResistances && isValidSupRes)
|
||||
{
|
||||
DrawSupportResistance(0, iSignal.supportResistances);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 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,436 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121X786
|
||||
// Description: X121 X786 Signal Provider ...
|
||||
//
|
||||
//
|
||||
// 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.condition.parser.lib.mq5"
|
||||
|
||||
//
|
||||
// CONDITIONS ...
|
||||
|
||||
//
|
||||
// Longs ...
|
||||
bool IsX786HasLongSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool long1 =
|
||||
//
|
||||
IsHKBullish(conditions) &&
|
||||
IsSMHKBullish(conditions) &&
|
||||
IsHullBullish(conditions, index) &&
|
||||
IsSSLCBullish(conditions, index) &&
|
||||
IsTrendBullish(conditions, index) &&
|
||||
IsRibbonBullish(conditions, index) &&
|
||||
IsBullishCandle(conditions.candles[1])
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool long2 =
|
||||
//
|
||||
IsTrendBullish(conditions) &&
|
||||
IsNewPeakOverLast(conditions) &&
|
||||
//
|
||||
(
|
||||
//
|
||||
IsSCLowBullish(conditions) &&
|
||||
(
|
||||
//
|
||||
IsMCLowBullish(conditions) ||
|
||||
IsLCLowBullish(conditions) ||
|
||||
IsHCLowBullish(conditions)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
long1
|
||||
//
|
||||
||
|
||||
//
|
||||
long2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Shorts ...
|
||||
bool IsX786HasShortSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool short1 =
|
||||
//
|
||||
IsHKBearish(conditions) &&
|
||||
IsSMHKBearish(conditions) &&
|
||||
IsHullBearish(conditions, index) &&
|
||||
IsSSLCBearish(conditions, index) &&
|
||||
IsTrendBearish(conditions, index) &&
|
||||
IsRibbonBearish(conditions, index) &&
|
||||
IsBearishCandle(conditions.candles[1])
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool short2 =
|
||||
//
|
||||
IsTrendBearish(conditions, index) &&
|
||||
IsNewValeUnderLast(conditions) &&
|
||||
//
|
||||
(
|
||||
//
|
||||
IsSCHighBearish(conditions) &&
|
||||
(
|
||||
//
|
||||
IsMCHighBearish(conditions) ||
|
||||
IsLCHighBearish(conditions) ||
|
||||
IsHCHighBearish(conditions)
|
||||
//
|
||||
)
|
||||
//
|
||||
)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
short1
|
||||
//
|
||||
||
|
||||
//
|
||||
short2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CALCULATIONS ...
|
||||
|
||||
//
|
||||
// Calculate Long Stop ...
|
||||
double CalculateX786LongStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double vale = conditions.xmanInfo.vales[0];
|
||||
double med = (conditions.xmanInfo.sLLs[0] + conditions.xmanInfo.mLLs[0]) / 2;
|
||||
double fl1 = conditions.xmanInfo.fibLevel1s[0];
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Long Take Profits ...
|
||||
double CalculateX786LongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry + rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry + PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Stop ...
|
||||
double CalculateX786ShortStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Take Profits ...
|
||||
double CalculateX786ShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry - rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry - PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNALS ...
|
||||
|
||||
//
|
||||
// Generate Signal ...
|
||||
bool GenerateX786Signal(
|
||||
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
|
||||
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
|
||||
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
|
||||
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(type);
|
||||
|
||||
//
|
||||
// Retrieve Entry Price ...
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
type);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
isLong
|
||||
? IsX786HasLongSignal(conditions)
|
||||
: IsX786HasShortSignal(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X786),
|
||||
conditions.signal.providers);
|
||||
|
||||
//
|
||||
double sl =
|
||||
//
|
||||
isLong
|
||||
? CalculateX786LongStop(conditions)
|
||||
: CalculateX786ShortStop(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double r2r = 3;
|
||||
|
||||
//
|
||||
double tp =
|
||||
//
|
||||
isLong
|
||||
? CalculateX786LongTarget(conditions, sl, entry, r2r)
|
||||
: CalculateX786ShortTarget(conditions, sl, entry, r2r)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double volume = 0.01;
|
||||
|
||||
//
|
||||
conditions.hasSignal = true;
|
||||
|
||||
//
|
||||
conditions.signal.type = type;
|
||||
conditions.signal.symbol = conditions.symbol;
|
||||
conditions.signal.period = conditions.period;
|
||||
conditions.signal.supportResistances = supportAndResistances;
|
||||
|
||||
//
|
||||
conditions.signal.sl = sl;
|
||||
conditions.signal.tp = tp;
|
||||
conditions.signal.r2r = r2r;
|
||||
conditions.signal.entry = entry;
|
||||
conditions.signal.volume = volume;
|
||||
conditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
if (generateSupports)
|
||||
{
|
||||
//
|
||||
// Generate Required Support Signals ...
|
||||
GenerateX786SignalSupports(conditions);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SUPPORTS ...
|
||||
|
||||
//
|
||||
// Generate Required Support Signals and Attached Them into
|
||||
// Exists Signal of Conditions ...
|
||||
int GenerateX786SignalSupports(
|
||||
X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// GUARDS ...
|
||||
|
||||
//
|
||||
// Check Can Force Close All X786 Long Signals or not ...
|
||||
bool CanX786ForceCloseLongs(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// 1- HK Min above FL 1 ...
|
||||
// 2- Trend Changed From Bullish To Bearish ...
|
||||
|
||||
//
|
||||
double minHK = GetHKMin(conditions);
|
||||
bool isMinHKOverFL1 = minHK > conditions.xmanInfo.fibLevel1s[0];
|
||||
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// isMinHKOverFL1 &&
|
||||
isTrendSwitchedToBearish
|
||||
//
|
||||
;
|
||||
// if (result) {
|
||||
// LogMessage("Test");
|
||||
// }
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Trailing Long Positions Stops ...
|
||||
bool CanX786TrailLongsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double prev = GetRibbonMin(conditions, 1);
|
||||
double current = GetRibbonMin(conditions);
|
||||
|
||||
//
|
||||
result = current > prev;
|
||||
if (result)
|
||||
{
|
||||
newSL = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSL = -1;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check For Trailing Short Positions Stops ...
|
||||
bool CanX786TrailShortsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double prev = GetRibbonMax(conditions, 1);
|
||||
double current = GetRibbonMax(conditions);
|
||||
|
||||
//
|
||||
result = current < prev;
|
||||
if (result)
|
||||
{
|
||||
newSL = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSL = -1;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,430 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121X92
|
||||
// Description: X121 X92 Signal Provider ...
|
||||
//
|
||||
//
|
||||
// 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.condition.parser.lib.mq5"
|
||||
|
||||
//
|
||||
// CONDITIONS ...
|
||||
|
||||
//
|
||||
// Longs ...
|
||||
bool IsX92HasLongSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool long1 =
|
||||
//
|
||||
IsNewPeak(conditions) &&
|
||||
IsValeSameAs(conditions) &&
|
||||
IsNewPeakUnderLast(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool long2 =
|
||||
//
|
||||
IsSMHKBullish(conditions, index) &&
|
||||
IsTrendBullish(conditions, index) &&
|
||||
IsBullishCandle(conditions.candles[index + 1])
|
||||
//
|
||||
&&
|
||||
//
|
||||
(conditions.candles[index + 1].low > GetSMHKMax(conditions, index) ||
|
||||
conditions.candles[index + 1].close > GetSMHKMax(conditions, index))
|
||||
//
|
||||
&&
|
||||
//
|
||||
conditions.xmanInfo.smhkHighs[index] == iSMHKHighest(conditions, index)
|
||||
//
|
||||
&&
|
||||
//
|
||||
IsSCLowBullish(conditions, index)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
long1
|
||||
//
|
||||
||
|
||||
//
|
||||
long2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Shorts ...
|
||||
bool IsX92HasShortSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool short1 =
|
||||
//
|
||||
IsNewVale(conditions) &&
|
||||
IsPeakSameAs(conditions) &&
|
||||
IsNewValeOverLast(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool short2 =
|
||||
//
|
||||
IsSMHKBearish(conditions, index) &&
|
||||
IsTrendBearish(conditions, index) &&
|
||||
IsBearishCandle(conditions.candles[index + 1])
|
||||
//
|
||||
&&
|
||||
//
|
||||
(conditions.candles[index + 1].high < GetSMHKMin(conditions, index) ||
|
||||
conditions.candles[index + 1].open < GetSMHKMin(conditions, index))
|
||||
//
|
||||
&&
|
||||
//
|
||||
conditions.xmanInfo.smhkHighs[index] == iSMHKLowest(conditions, index)
|
||||
//
|
||||
&&
|
||||
//
|
||||
IsSCHighBearish(conditions, index)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
short1
|
||||
//
|
||||
||
|
||||
//
|
||||
short2
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CALCULATIONS ...
|
||||
|
||||
//
|
||||
// Calculate Long Stop ...
|
||||
double CalculateX92LongStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double vale = conditions.xmanInfo.vales[0];
|
||||
double med = (conditions.xmanInfo.sLLs[0] + conditions.xmanInfo.mLLs[0]) / 2;
|
||||
double fl1 = conditions.xmanInfo.fibLevel1s[0];
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Long Take Profits ...
|
||||
double CalculateX92LongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry + rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry + PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Stop ...
|
||||
double CalculateX92ShortStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Take Profits ...
|
||||
double CalculateX92ShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry - rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry - PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNALS ...
|
||||
|
||||
//
|
||||
// Generate Signal ...
|
||||
bool GenerateX92Signal(
|
||||
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
|
||||
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
|
||||
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
|
||||
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(type);
|
||||
|
||||
//
|
||||
// Retrieve Entry Price ...
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
type);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
isLong
|
||||
? IsX92HasLongSignal(conditions)
|
||||
: IsX92HasShortSignal(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(X92),
|
||||
conditions.signal.providers);
|
||||
|
||||
//
|
||||
double sl =
|
||||
//
|
||||
isLong
|
||||
? CalculateX92LongStop(conditions)
|
||||
: CalculateX92ShortStop(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double r2r = 3;
|
||||
|
||||
//
|
||||
double tp =
|
||||
//
|
||||
isLong
|
||||
? CalculateX92LongTarget(conditions, sl, entry, r2r)
|
||||
: CalculateX92ShortTarget(conditions, sl, entry, r2r)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double volume = 0.01;
|
||||
|
||||
//
|
||||
conditions.hasSignal = true;
|
||||
|
||||
//
|
||||
conditions.signal.type = type;
|
||||
conditions.signal.symbol = conditions.symbol;
|
||||
conditions.signal.period = conditions.period;
|
||||
conditions.signal.supportResistances = supportAndResistances;
|
||||
|
||||
//
|
||||
conditions.signal.sl = sl;
|
||||
conditions.signal.tp = tp;
|
||||
conditions.signal.r2r = r2r;
|
||||
conditions.signal.entry = entry;
|
||||
conditions.signal.volume = volume;
|
||||
conditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
if (generateSupports)
|
||||
{
|
||||
//
|
||||
// Generate Required Support Signals ...
|
||||
GenerateX92SignalSupports(conditions);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SUPPORTS ...
|
||||
|
||||
//
|
||||
// Generate Required Support Signals and Attached Them into
|
||||
// Exists Signal of Conditions ...
|
||||
int GenerateX92SignalSupports(
|
||||
X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// GUARDS ...
|
||||
|
||||
//
|
||||
// Check Can Force Close All X92 Long Signals or not ...
|
||||
bool CanX92ForceCloseLongs(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// 1- HK Min above FL 1 ...
|
||||
// 2- Trend Changed From Bullish To Bearish ...
|
||||
|
||||
//
|
||||
double minHK = GetHKMin(conditions);
|
||||
bool isMinHKOverFL1 = minHK > conditions.xmanInfo.fibLevel1s[0];
|
||||
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
// isMinHKOverFL1 &&
|
||||
isTrendSwitchedToBearish
|
||||
//
|
||||
;
|
||||
// if (result) {
|
||||
// LogMessage("Test");
|
||||
// }
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Trailing Long Positions Stops ...
|
||||
bool CanX92TrailLongsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double prev = GetRibbonMin(conditions, 1);
|
||||
double current = GetRibbonMin(conditions);
|
||||
|
||||
//
|
||||
result = current > prev;
|
||||
if (result)
|
||||
{
|
||||
newSL = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSL = -1;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check For Trailing Short Positions Stops ...
|
||||
bool CanX92TrailShortsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
double prev = GetRibbonMax(conditions, 1);
|
||||
double current = GetRibbonMax(conditions);
|
||||
|
||||
//
|
||||
result = current < prev;
|
||||
if (result)
|
||||
{
|
||||
newSL = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSL = -1;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121XTEST
|
||||
// Description: X121 XTEST Signal Provider ...
|
||||
//
|
||||
//
|
||||
// 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.condition.parser.lib.mq5"
|
||||
|
||||
//
|
||||
// CONDITIONS ...
|
||||
|
||||
//
|
||||
// Longs ...
|
||||
bool IsXTESTHasLongSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isTrendBullish = IsTrendBullish(conditions, index);
|
||||
bool isCandleBullish = IsBullishCandle(conditions.candles[1]);
|
||||
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
|
||||
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trends[1] &&
|
||||
conditions.xmanInfo.trends[0] > conditions.xmanInfo.trendChanges[0].from;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
isValidTrend &&
|
||||
isTrendBullish &&
|
||||
isCandleBullish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Shorts ...
|
||||
bool IsXTESTHasShortSignal(
|
||||
const X121MarketConditions &conditions, // Specified Conditions
|
||||
int index = 0 // Array Index
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isTrendBearish = IsTrendBearish(conditions, index);
|
||||
bool isCandleBearish = IsBearishCandle(conditions.candles[1]);
|
||||
bool isValidTrend = ArraySize(conditions.xmanInfo.trendChanges) > 2 &&
|
||||
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trends[1] &&
|
||||
conditions.xmanInfo.trends[0] < conditions.xmanInfo.trendChanges[0].from;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
isValidTrend &&
|
||||
isTrendBearish &&
|
||||
isCandleBearish
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// CALCULATIONS ...
|
||||
|
||||
//
|
||||
// Calculate Long Stop ...
|
||||
double CalculateXTESTLongStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
conditions.xmanInfo.vales[0]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Long Take Profits ...
|
||||
double CalculateXTESTLongTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry + rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry + PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
double peak = conditions.xmanInfo.peaks[1];
|
||||
result =
|
||||
entry >= peak
|
||||
? entry + PointToPrice(conditions.symbol, 60)
|
||||
: peak;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Stop ...
|
||||
double CalculateXTESTShortStop(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
conditions.xmanInfo.peaks[0]
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Short Take Profits ...
|
||||
double CalculateXTESTShortTarget(const X121MarketConditions &conditions, double sl, double entry, double r2r = 1)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
if (sl > 0 && entry > 0 && r2r > 0)
|
||||
{
|
||||
//
|
||||
double riskPrice = MathAbs(entry - sl);
|
||||
double rewardPrice = riskPrice * r2r;
|
||||
|
||||
//
|
||||
result = entry - rewardPrice;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = entry - PointToPrice(conditions.symbol, 60);
|
||||
}
|
||||
|
||||
//
|
||||
double vale = conditions.xmanInfo.vales[1];
|
||||
result =
|
||||
entry <= vale
|
||||
? entry - PointToPrice(conditions.symbol, 60)
|
||||
: vale;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SIGNALS ...
|
||||
|
||||
//
|
||||
// Generate Signal ...
|
||||
bool GenerateXTESTSignal(
|
||||
X121MarketConditions &conditions, // Specified Conditions which Holds Signal also ...
|
||||
const XOHCLSupRes &supportAndResistances, // Specified Support and Resistances ...
|
||||
ENUM_POSITION_TYPE type, // Specified Which Signal Type must be Generated ...
|
||||
bool generateSupports = false // Specified Support Signals also Generated and Attached or not ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isLong = IsLong(type);
|
||||
|
||||
//
|
||||
// Retrieve Entry Price ...
|
||||
double entry = GetEntry(
|
||||
conditions.symbol,
|
||||
type);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
isLong
|
||||
? IsXTESTHasLongSignal(conditions)
|
||||
: IsXTESTHasShortSignal(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
ToString(XTEST),
|
||||
conditions.signal.providers);
|
||||
|
||||
//
|
||||
double sl =
|
||||
//
|
||||
isLong
|
||||
? CalculateXTESTLongStop(conditions)
|
||||
: CalculateXTESTShortStop(conditions)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double r2r = 1.5;
|
||||
|
||||
//
|
||||
double tp =
|
||||
//
|
||||
isLong
|
||||
? CalculateXTESTLongTarget(conditions, sl, entry, r2r)
|
||||
: CalculateXTESTShortTarget(conditions, sl, entry, r2r)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
double volume = 0.01;
|
||||
|
||||
//
|
||||
conditions.hasSignal = true;
|
||||
|
||||
//
|
||||
conditions.signal.type = type;
|
||||
conditions.signal.symbol = conditions.symbol;
|
||||
conditions.signal.period = conditions.period;
|
||||
conditions.signal.supportResistances = supportAndResistances;
|
||||
|
||||
//
|
||||
conditions.signal.sl = 0; // sl;
|
||||
conditions.signal.tp = tp;
|
||||
conditions.signal.r2r = r2r;
|
||||
conditions.signal.entry = entry;
|
||||
conditions.signal.volume = volume;
|
||||
conditions.signal.mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
if (generateSupports)
|
||||
{
|
||||
//
|
||||
// Generate Required Support Signals ...
|
||||
GenerateXTESTSignalSupports(conditions);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SUPPORTS ...
|
||||
|
||||
//
|
||||
// Generate Required Support Signals and Attached Them into
|
||||
// Exists Signal of Conditions ...
|
||||
int GenerateXTESTSignalSupports(
|
||||
X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// GUARDS ...
|
||||
|
||||
//
|
||||
// Check Can Force Close All XTEST Long Signals or not ...
|
||||
bool CanXTESTForceCloseLongs(const X121MarketConditions &conditions)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
bool isTrendSwitchedToBearish = IsTrendSwitchedToBearish(conditions);
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Trailing Long Positions Stops ...
|
||||
bool CanXTESTTrailLongsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check For Trailing Short Positions Stops ...
|
||||
bool CanXTESTTrailShortsStop(
|
||||
const X121MarketConditions &conditions,
|
||||
double &newSL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user