Files
MQL5Data/Projects/XUSPY5/Experts/x-saherelm.xuspy5.ea.mq5
T

348 lines
7.0 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Expert Advisor
// ----------------------------------------
// Name: XAUUSD
// Description: this is an expert controller
// advisors which provides a mechanism for use them ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XUSPY5 EA"
#property strict
//
// START Inputs ...
//
input group "Commons";
//
// END Inputs ...
//
//
// START Including Providers ...
//
//
// Logger Library ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// Alert Library ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
//
// Draw Library ...
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
// XUSPY5 Signal Provider ...
#include "../Providers/x-saherelm.xuspy5.provider.lib.mq5"
//
// END Including Providers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
bool isXUSPY5NewHour;
bool isXUSPY5NewDay;
bool isXUSPY5NewWeek;
bool isXUSPY5NewMonth;
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Event Handlers ...
//
//
// Initialization ...
int OnInit()
{
//
logTag = "XUSPY5EA";
drawPrefix = logTag;
alertPrefix = logTag;
//
// Apply default Chart Style for EA ...
ApplyChartStyle();
//
// Reset Timings ...
ResetTiming();
//
// Validate Inputs ...
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Initialize XUSPY5 Provider ...
if (!XUSPY5InitSignalProviderLibrary())
{
return INIT_PARAMETERS_INCORRECT;
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// Here we can handle De Initialization Reasons ...
//
// De Initialize XUSPY5 Provider ...
XUSPY5DeinitSignalProviderLibrary(reason);
//
// De Init XDraw Library ...
// OnDeinitDrawLibrary();
}
//
// On Tick Handler ...
void OnTick()
{
//
// Handle Monthly Alert ...
bool isFirstMonth = xMonth == -1;
isXUSPY5NewMonth = IsNewMonth();
bool canMonthlyAlert =
isXUSPY5NewMonth &&
xUSPY5EnableAlerts &&
xUSPY5EnableMonthlyAlerts;
bool canMonthlyReport =
!isFirstMonth &&
canMonthlyAlert &&
xUSPY5EnableMonthlyReports;
if (canMonthlyAlert)
{
//
string message = "New Month ...";
//
// Prepare Monthly Report ...
if (canMonthlyReport)
{
//
string report = xUSPY5Reporter.GenerateReportString(XREPORT_MONTHLY);
//
message = "Last Month Report:\n" + report;
}
//
// Reset Report ...
xUSPY5Reporter.Reset(XREPORT_MONTHLY);
//
SendAlert(message);
}
//
// Handle Weekly Alert ...
bool isFirstWeek = xDayOfWeek == -1;
isXUSPY5NewWeek = IsNewWeek();
bool canWeeklyAlert =
isXUSPY5NewWeek &&
xUSPY5EnableAlerts &&
xUSPY5EnableWeeklyAlerts;
bool canWeeklyReport =
!isFirstWeek &&
canWeeklyAlert &&
xUSPY5EnableWeeklyReports;
if (canWeeklyAlert)
{
//
string message = "New Week ...";
//
// Prepare Weekly Report ...
if (canWeeklyReport)
{
//
string report = xUSPY5Reporter.GenerateReportString(XREPORT_WEEKLY);
//
message = "Last Week Report:\n" + report;
}
//
// Reset Report ...
xUSPY5Reporter.Reset(XREPORT_WEEKLY);
//
SendAlert(message);
}
//
// Handle Daily Alert ...
bool isFirstDay = xDay == -1;
isXUSPY5NewDay = IsNewDay();
bool canDailyAlert =
isXUSPY5NewDay &&
xUSPY5EnableAlerts &&
xUSPY5EnableDailyAlerts;
bool canDailyReport =
!isFirstDay &&
canDailyAlert &&
xUSPY5EnableDailyReports;
if (canDailyAlert)
{
//
string message = "New Day ...";
//
// Prepare Daily Report ...
if (canDailyReport)
{
//
string report = xUSPY5Reporter.GenerateReportString(XREPORT_DAILY);
//
message = "Last Week Report:\n" + report;
}
//
// Reset Report ...
xUSPY5Reporter.Reset(XREPORT_DAILY);
//
SendAlert(message);
}
//
// Handle Hourly Alert ...
bool isFirstHour = xHour == -1;
isXUSPY5NewHour = IsNewHour();
bool canHourlyAlert =
isXUSPY5NewHour &&
xUSPY5EnableAlerts &&
xUSPY5EnableHourlyAlerts;
if (canHourlyAlert)
{
//
string message = "New Hour ...";
//
SendAlert(message);
}
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
{
//
// Handle Processing on XUSPY5 Signal Provider ...
XUSPY5SignalProviderDoControlState();
}
//
if (!IsNewCandle())
{
return;
}
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
{
//
// Handle Processing on XUSPY5 Signal Provider ...
XUSPY5SignalProviderHandleTick();
}
}
//
// Handle Trade Events ...
void OnTrade()
{
//
// Prevent Going Forward if user Disable it ...
if (xUSPY5EnableProvider)
{
//
// Handle Processing Trades on XUSPY5 Signal Provider ...
XUSPY5SignalProviderHandleTrade();
}
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
//
// Validate Input Args for Initialization ...
bool ValidateInputs()
{
//
bool result = false;
//
// Validate Args ...
//
// Validate XUSPY5 Provider Inputs ...
result = XUSPY5ValidateInputs();
if (!result)
{
return false;
}
//
// Logging State ...
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
LogMessage(message);
//
return result;
}
//
// END Functions ...
//