prepare workspace for start implementing XCHMACC in XUSCHF5 EA ...

This commit is contained in:
2024-02-24 08:55:07 +03:30
parent 558928d1a2
commit f8139920bc
36 changed files with 11057 additions and 9086 deletions
@@ -1,283 +0,0 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XEU5 Signal Provider Library Inputs
// -----------------------------------------------------------
//
// 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 Logger ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Include Classes ...
#include "../Classes/x-saherelm.class.lib.mq5"
//
input group "XEU5 Provider";
//
// Commonly Used Configurations ...
input group "XEU5 Common";
//
// Provider ...
input bool xEU5EnableProvider = true; // Enable Provider
input int xEU5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
//
// Alerts ...
input bool xEU5EnableAlerts = true; // Enable Events Alert
input bool xEU5EnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xEU5EnableDailyAlerts = false; // Send Alert on each new Day
input bool xEU5EnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xEU5EnableMonthlyAlerts = false; // Send Alert on each new Month
//
// Reports ...
input bool xEU5EnableDailyReports = false; // Send Report on each new Day
input bool xEU5EnableWeeklyReports = false; // Send Report on each new Week
input bool xEU5EnableMonthlyReports = false; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
input group "XEU5 Trader";
input int xEU5MagicNumber = 16940560; // Trader MagicNumber
input int xEU5Slippage = 10; // Trader Slippage
//
// Trades Management Configurations ...
input group "XEU5 Trade Management";
input bool xEU5AllowLongTrades = true; // Allow Long Trades
input bool xEU5AllowShortTrades = true; // Allow Short Trades
//
// Risk Management Configurations ...
input group "XEU5 Risk Management";
//
// Trade Count ...
input int xEU5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
input ENUM_X_CROSS_SIGNAL_METHOD xEU5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xEU5MaxAllowedTradeAge = 1500; // Detect Long Time Trades
input ENUM_X_GUARD_ACTIONS xEU5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
input double xEU5StaticVolumeFactor = 0.0002; // Static Volume baesd on Balance
input ENUM_STATIC_VOLUME_METHODS xEU5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
input double xEU5VolumeMultiplier = 0; // Volume Increase Multiplier
input double xEU5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
input double xEU5MaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
input double xEU5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
//
// Trade Profits ...
input double xEU5MinRewardInPips = 6; // Minimum Reward Per Trade in Pips
input double xEU5RiskFreeStepInPips = 0; // Make Trades Risk Free Steps in Pips
input double xEU5RiskFreeRate = 0; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xEU5CriticalDrawDownFactor = 0.20; // Critical Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xEU5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // Specify Guard Action on Critical Drawdown
input double xEU5MaxAllowedDrawDownFactor = 0.25; // Max Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xEU5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Max Allowed Drawdown
input int xEU5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
//
// Account Conditions for Trading ...
input double xEU5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
input double xEU5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
//
// May be Used Later as Input Params ...
bool xEU5UseVirtualTPSl = false; // Use Virtual TP SL
bool xEU5EnableSignalAlerts = false; // Send Signal Alert
//
// Validate Inputs before Initialization ...
bool XEU5ValidateInputs()
{
//
bool result = false;
//
// Implement Other Verifications ...
//
// Check Trading Availability ...
bool isTradeAvailable = xEU5AllowLongTrades || xEU5AllowShortTrades;
if (!isTradeAvailable)
{
LogMessage("XEU5 => Warning: Trading disabled ...");
}
//
// Chekc Number of reading items per tick ...
result = xEU5NumberOfItemsPerTick >= 5;
if (!result)
{
//
LogMessage("XEU5 invalid Number of items Reading Per Tick ...");
//
return result;
}
//
// Check Max Allowed Trades Count ...
result = isTradeAvailable && xEU5MaxAllowedTrades >= 1;
if (!result)
{
//
LogMessage("XEU5 Number of Trades not valid ...");
//
return result;
}
//
// Check Free Margin ...
result =
isTradeAvailable &&
xEU5FreeMarginFactorForOpenTrades > 0 &&
xEU5FreeMarginFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XEU5 Invalid Free Margin ...");
//
return result;
}
//
// Check min Balance for Open Trades ...
result =
isTradeAvailable &&
xEU5BalanceFactorForOpenTrades > 0 &&
xEU5BalanceFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XEU5 Invalid Min Balance for Open Trades ...");
//
return result;
}
//
// Check Min Reward Per Trade ...
result = xEU5MinRewardInPips > 0;
if (!result)
{
//
LogMessage("XEU5 Invalid Min Reward Per Trade ...");
//
return result;
}
//
// Check Trades Volume ...
result = xEU5StaticVolumeFactor > 0;
if (!result)
{
//
LogMessage("XEU5 Invalid Static Volume ...");
//
return result;
}
//
// Check Volume Multiplier ...
result = xEU5VolumeMultiplier >= 0;
if (!result)
{
//
LogMessage("XEU5 Invalid Volume Multiplier ...");
//
return result;
}
//
result =
xEU5CriticalDrawDownFactor == 0 || (xEU5CriticalDrawDownFactor > 0 &&
xEU5CriticalDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XEU5 Invalid Critical DrawDown Factor ...");
//
return result;
}
//
result =
xEU5MaxAllowedDrawDownFactor == 0 || (xEU5MaxAllowedDrawDownFactor > 0 &&
xEU5MaxAllowedDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XEU5 Invalid Max Allowed DrawDown Factor ...");
//
return result;
}
//
// Check Guard Actions ...
//
result =
xEU5CriticalDrawDownFactor > 0 &&
xEU5CriticalDrawDownFactor < 1 &&
xEU5MaxAllowedDrawDownFactor > 0 &&
xEU5MaxAllowedDrawDownFactor < 1;
if (!result)
{
//
LogMessage("XEU5 For Critical Drawdown, you have to Specify Max Drawdown also ...");
//
return result;
}
//
result = xEU5CriticalDrawDownFactor > 0 && xEU5CriticalDrawDownFactor < xEU5MaxAllowedDrawDownFactor;
if (!result)
{
//
LogMessage("XEU5 Critical Drawdown must Smaller than Max Drawdown ...");
//
return result;
}
//
if (xEU5CriticalDrawDownFactor > 0 && xEU5CriticalGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XEU5 IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
}
//
if (xEU5MaxAllowedDrawDownFactor > 0 && xEU5MaxAllowedGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XEU5 IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
}
//
result = true;
//
return result;
}
@@ -254,14 +254,14 @@ struct XMarketConditions
// //
// //
class XCProvider : public XCBase class XCPriver : public XCBase
{ {
// //
// Public ... // Public ...
public: public:
// //
// Constructor ... // Constructor ...
XCProvider( XCPriver(
// //
// Common Requirements ... // Common Requirements ...
string xSymbol, // Which Symbol is Used string xSymbol, // Which Symbol is Used
@@ -285,9 +285,9 @@ public:
bool xSIAllowShortSignals, // Allow Short Signals bool xSIAllowShortSignals, // Allow Short Signals
// //
// XTSFI ... // XTSFI ...
bool xTSFIEnableSignaller, // Enable Signaller bool XTSFIEnableSignaller, // Enable Signaller
bool xTSFIAllowLongSignals, // Allow Long Signals bool XTSFIAllowLongSignals, // Allow Long Signals
bool xTSFIAllowShortSignals, // Allow Short Signals bool XTSFIAllowShortSignals, // Allow Short Signals
// //
// XOBDLH ... // XOBDLH ...
bool xOBDLHEnableSignaller, // Enable Signaller bool xOBDLHEnableSignaller, // Enable Signaller
@@ -331,9 +331,9 @@ public:
// //
// XTSFI ... // XTSFI ...
mXTSFIEnableSignaller = xTSFIEnableSignaller; mXTSFIEnableSignaller = XTSFIEnableSignaller;
mXTSFIAllowLongSignals = xTSFIAllowLongSignals; mXTSFIAllowLongSignals = XTSFIAllowLongSignals;
mXTSFIAllowShortSignals = xTSFIAllowShortSignals; mXTSFIAllowShortSignals = XTSFIAllowShortSignals;
// //
// XOBDLH ... // XOBDLH ...
@@ -362,7 +362,7 @@ public:
// //
// Deconstructor ... // Deconstructor ...
~XCProvider() {} ~XCPriver() {}
// //
// START Common Functions ... // START Common Functions ...
+8 -8
View File
@@ -38,14 +38,6 @@ Resolve XUSCHF5 XTSFI All Critical Guard Attacks in All Markets ...
Resolve XUSCHF5 XTSFI All Guard Attacks in All Markets ... Resolve XUSCHF5 XTSFI All Guard Attacks in All Markets ...
XOBDLH
--------
Resolve XUSCHF5 XOBDLH All Stopouts in All Markets ...
Resolve XUSCHF5 XOBDLH Longs All Critical Guard Attacks in AMarkets-Real ...
Resolve XUSCHF5 XOBDLH Shorts All Critical Guard Attacks in All Markets ...
Resolve XUSCHF5 XOBDLH All Guard Attacks in All Markets ...
XCHMACC XCHMACC
-------- --------
Resolve XUSCHF5 XCHMACC All Stopouts in All Markets ... Resolve XUSCHF5 XCHMACC All Stopouts in All Markets ...
@@ -54,6 +46,14 @@ Resolve XUSCHF5 XCHMACC Shorts All Critical Guard Attacks in All Markets ...
Resolve XUSCHF5 XCHMACC All Guard Attacks in All Markets ... Resolve XUSCHF5 XCHMACC All Guard Attacks in All Markets ...
XOBDLH
--------
Resolve XUSCHF5 XOBDLH All Stopouts in All Markets ...
Resolve XUSCHF5 XOBDLH Longs All Critical Guard Attacks in AMarkets-Real ...
Resolve XUSCHF5 XOBDLH Shorts All Critical Guard Attacks in All Markets ...
Resolve XUSCHF5 XOBDLH All Guard Attacks in All Markets ...
XCHMAMX XCHMAMX
-------- --------
Resolve XUSCHF5 XCHMAMX All Stopouts in All Markets ... Resolve XUSCHF5 XCHMAMX All Stopouts in All Markets ...
@@ -17,21 +17,20 @@
#property copyright "Copyright 2023, SaherElm IT Center" #property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir" #property link "https://saherelm.ir"
#property version "1.00" #property version "1.00"
#property description "SaherElm XEU5 EA" #property description "SaherElm XUSCHF5 EA"
#property strict #property strict
// //
// START Inputs ... // START Inputs ...
// //
//
input group "Commons"; input group "Commons";
// //
// XCTIMER inputs ... // XCTIMER inputs ...
input bool xEU5ShowCandleTimer = true; // Show Condle Remaining Time input bool xUSCHF5ShowCandleTimer = true; // Show Condle Remaining Time
input color xEU5CandleTimerColot = clrYellow; // Candle Timer Color input color xUSCHF5CandleTimerColot = clrYellow; // Candle Timer Color
input ENUM_BASE_CORNER xEU5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer input ENUM_BASE_CORNER xUSCHF5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer
// //
// END Inputs ... // END Inputs ...
@@ -58,8 +57,8 @@ input ENUM_BASE_CORNER xEU5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to S
#include "../Libraries/x-saherelm.draw.lib.mq5" #include "../Libraries/x-saherelm.draw.lib.mq5"
// //
// XEU5 Signal Provider ... // XUSCHF5 Signal Provider ...
#include "../Providers/x-saherelm.xeu5.provider.lib.mq5" #include "../Providers/x-saherelm.xuschf5.provider.lib.mq5"
// //
// END Including Providers ... // END Including Providers ...
@@ -68,13 +67,13 @@ input ENUM_BASE_CORNER xEU5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to S
// //
// START Global Definitions: Variables, Properties and etc ... // START Global Definitions: Variables, Properties and etc ...
// //
bool isXEU5NewHour; bool isXUSCHF5NewHour;
bool isXEU5NewDay; bool isXUSCHF5NewDay;
bool isXEU5NewWeek; bool isXUSCHF5NewWeek;
bool isXEU5NewMonth; bool isXUSCHF5NewMonth;
// //
int xEU5CTimerHandler = INVALID_HANDLE; int xUSCHF5CTimerHandler = INVALID_HANDLE;
// //
// END Global Definitions: Variables, Properties and etc ... // END Global Definitions: Variables, Properties and etc ...
// //
@@ -88,7 +87,7 @@ int xEU5CTimerHandler = INVALID_HANDLE;
int OnInit() int OnInit()
{ {
// //
logTag = "XEU5EA"; logTag = "XUSCHF5EA";
drawPrefix = logTag; drawPrefix = logTag;
alertPrefix = logTag; alertPrefix = logTag;
@@ -108,17 +107,17 @@ int OnInit()
} }
// //
// Initialize XEU5 Provider ... // Initialize XUSCHF5 Provider ...
if (!XEU5InitSignalProviderLibrary()) if (!XUSCHF5InitSignalProviderLibrary())
{ {
return INIT_PARAMETERS_INCORRECT; return INIT_PARAMETERS_INCORRECT;
} }
// //
// Init XCTimer ... // Init XCTimer ...
if (xEU5ShowCandleTimer) if (xUSCHF5ShowCandleTimer)
{ {
if (!XEU5CTimerInit()) if (!XUSCHF5CTimerInit())
{ {
return INIT_FAILED; return INIT_FAILED;
} }
@@ -149,15 +148,15 @@ void OnDeinit(const int reason)
// Here we can handle De Initialization Reasons ... // Here we can handle De Initialization Reasons ...
// //
// De Initialize XEU5 Provider ... // De Initialize XUSCHF5 Provider ...
XEU5DeinitSignalProviderLibrary(reason); XUSCHF5DeinitSignalProviderLibrary(reason);
// //
// De Init XDraw Library ... // De Init XDraw Library ...
// OnDeinitDrawLibrary(); // OnDeinitDrawLibrary();
// //
IndicatorRelease(xEU5CTimerHandler); IndicatorRelease(xUSCHF5CTimerHandler);
} }
// //
@@ -167,15 +166,15 @@ void OnTick()
// //
// Handle Monthly Alert ... // Handle Monthly Alert ...
bool isFirstMonth = xMonth == -1; bool isFirstMonth = xMonth == -1;
isXEU5NewMonth = IsNewMonth(); isXUSCHF5NewMonth = IsNewMonth();
bool canMonthlyAlert = bool canMonthlyAlert =
isXEU5NewMonth && isXUSCHF5NewMonth &&
xEU5EnableAlerts && xUSCHF5EnableAlerts &&
xEU5EnableMonthlyAlerts; xUSCHF5EnableMonthlyAlerts;
bool canMonthlyReport = bool canMonthlyReport =
!isFirstMonth && !isFirstMonth &&
canMonthlyAlert && canMonthlyAlert &&
xEU5EnableMonthlyReports; xUSCHF5EnableMonthlyReports;
if (canMonthlyAlert) if (canMonthlyAlert)
{ {
// //
@@ -186,7 +185,7 @@ void OnTick()
if (canMonthlyReport) if (canMonthlyReport)
{ {
// //
string report = xEU5Reporter.GenerateReportString(XREPORT_MONTHLY); string report = xUSCHF5Reporter.GenerateReportString(XREPORT_MONTHLY);
// //
message = "Last Month Report:\n" + report; message = "Last Month Report:\n" + report;
@@ -194,7 +193,7 @@ void OnTick()
// //
// Reset Report ... // Reset Report ...
xEU5Reporter.Reset(XREPORT_MONTHLY); xUSCHF5Reporter.Reset(XREPORT_MONTHLY);
// //
SendAlert(message); SendAlert(message);
@@ -203,15 +202,15 @@ void OnTick()
// //
// Handle Weekly Alert ... // Handle Weekly Alert ...
bool isFirstWeek = xDayOfWeek == -1; bool isFirstWeek = xDayOfWeek == -1;
isXEU5NewWeek = IsNewWeek(); isXUSCHF5NewWeek = IsNewWeek();
bool canWeeklyAlert = bool canWeeklyAlert =
isXEU5NewWeek && isXUSCHF5NewWeek &&
xEU5EnableAlerts && xUSCHF5EnableAlerts &&
xEU5EnableWeeklyAlerts; xUSCHF5EnableWeeklyAlerts;
bool canWeeklyReport = bool canWeeklyReport =
!isFirstWeek && !isFirstWeek &&
canWeeklyAlert && canWeeklyAlert &&
xEU5EnableWeeklyReports; xUSCHF5EnableWeeklyReports;
if (canWeeklyAlert) if (canWeeklyAlert)
{ {
// //
@@ -222,7 +221,7 @@ void OnTick()
if (canWeeklyReport) if (canWeeklyReport)
{ {
// //
string report = xEU5Reporter.GenerateReportString(XREPORT_WEEKLY); string report = xUSCHF5Reporter.GenerateReportString(XREPORT_WEEKLY);
// //
message = "Last Week Report:\n" + report; message = "Last Week Report:\n" + report;
@@ -230,7 +229,7 @@ void OnTick()
// //
// Reset Report ... // Reset Report ...
xEU5Reporter.Reset(XREPORT_WEEKLY); xUSCHF5Reporter.Reset(XREPORT_WEEKLY);
// //
SendAlert(message); SendAlert(message);
@@ -239,15 +238,15 @@ void OnTick()
// //
// Handle Daily Alert ... // Handle Daily Alert ...
bool isFirstDay = xDay == -1; bool isFirstDay = xDay == -1;
isXEU5NewDay = IsNewDay(); isXUSCHF5NewDay = IsNewDay();
bool canDailyAlert = bool canDailyAlert =
isXEU5NewDay && isXUSCHF5NewDay &&
xEU5EnableAlerts && xUSCHF5EnableAlerts &&
xEU5EnableDailyAlerts; xUSCHF5EnableDailyAlerts;
bool canDailyReport = bool canDailyReport =
!isFirstDay && !isFirstDay &&
canDailyAlert && canDailyAlert &&
xEU5EnableDailyReports; xUSCHF5EnableDailyReports;
if (canDailyAlert) if (canDailyAlert)
{ {
// //
@@ -258,7 +257,7 @@ void OnTick()
if (canDailyReport) if (canDailyReport)
{ {
// //
string report = xEU5Reporter.GenerateReportString(XREPORT_DAILY); string report = xUSCHF5Reporter.GenerateReportString(XREPORT_DAILY);
// //
message = "Last Week Report:\n" + report; message = "Last Week Report:\n" + report;
@@ -266,7 +265,7 @@ void OnTick()
// //
// Reset Report ... // Reset Report ...
xEU5Reporter.Reset(XREPORT_DAILY); xUSCHF5Reporter.Reset(XREPORT_DAILY);
// //
SendAlert(message); SendAlert(message);
@@ -275,11 +274,11 @@ void OnTick()
// //
// Handle Hourly Alert ... // Handle Hourly Alert ...
bool isFirstHour = xHour == -1; bool isFirstHour = xHour == -1;
isXEU5NewHour = IsNewHour(); isXUSCHF5NewHour = IsNewHour();
bool canHourlyAlert = bool canHourlyAlert =
isXEU5NewHour && isXUSCHF5NewHour &&
xEU5EnableAlerts && xUSCHF5EnableAlerts &&
xEU5EnableHourlyAlerts; xUSCHF5EnableHourlyAlerts;
if (canHourlyAlert) if (canHourlyAlert)
{ {
// //
@@ -291,33 +290,33 @@ void OnTick()
// //
// Prevent Going Forward if user Disable it ... // Prevent Going Forward if user Disable it ...
if (xEU5EnableProvider) if (xUSCHF5EnableProvider)
{ {
// //
// Handle Processing on XEU5 Signal Provider ... // Handle Processing on XUSCHF5 Signal Provider ...
XEU5SignalProviderDoControlState(); XUSCHF5SignalProviderDoControlState();
} }
// //
// Check Can Ignore Tick or not .. // Check Can Ignore Tick or not ..
bool canIgnoreTick = xEU5IsTestMode bool canIgnoreTick = xUSCHF5IsTestMode
? !IsNewCandle() ? !IsNewCandle()
: !IsNewCandle() && xEU5WaitUntilNextCandle; : !IsNewCandle() && xUSCHF5WaitUntilNextCandle;
if (canIgnoreTick) if (canIgnoreTick)
{ {
return; return;
} }
// //
xEU5WaitUntilNextCandle = false; xUSCHF5WaitUntilNextCandle = false;
// //
// Prevent Going Forward if user Disable it ... // Prevent Going Forward if user Disable it ...
if (xEU5EnableProvider) if (xUSCHF5EnableProvider)
{ {
// //
// Handle Processing on XEU5 Signal Provider ... // Handle Processing on XUSCHF5 Signal Provider ...
XEU5SignalProviderHandleTick(); XUSCHF5SignalProviderHandleTick();
} }
} }
@@ -328,11 +327,11 @@ void OnTrade()
// //
// Prevent Going Forward if user Disable it ... // Prevent Going Forward if user Disable it ...
if (xEU5EnableProvider) if (xUSCHF5EnableProvider)
{ {
// //
// Handle Processing Trades on XEU5 Signal Provider ... // Handle Processing Trades on XUSCHF5 Signal Provider ...
XEU5SignalProviderHandleTrade(); XUSCHF5SignalProviderHandleTrade();
} }
} }
@@ -355,8 +354,8 @@ bool ValidateInputs()
// Validate Args ... // Validate Args ...
// //
// Validate XEU5 Provider Inputs ... // Validate XUSCHF5 Provider Inputs ...
result = XEU5ValidateInputs(); result = XUSCHF5ValidateInputs();
if (!result) if (!result)
{ {
return false; return false;
@@ -371,24 +370,24 @@ bool ValidateInputs()
return result; return result;
} }
bool XEU5CTimerInit() bool XUSCHF5CTimerInit()
{ {
// //
bool result = true; bool result = true;
// //
xEU5CTimerHandler = iCustom( xUSCHF5CTimerHandler = iCustom(
_Symbol, _Symbol,
_Period, _Period,
"x-saherelm.xctimer.indicator", "x-saherelm.xctimer.indicator",
// //
// Inputs ... // Inputs ...
xEU5CandleTimerColot, xUSCHF5CandleTimerColot,
xEU5CandleTimerCorner xUSCHF5CandleTimerCorner);
);
// //
if (xEU5CTimerHandler == INVALID_HANDLE) { if (xUSCHF5CTimerHandler == INVALID_HANDLE)
{
result = false; result = false;
} }
@@ -0,0 +1,283 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XUSCHF5 Signal Provider Library Inputs
// -----------------------------------------------------------
//
// 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 Logger ...
#include "../Libraries/x-saherelm.log.lib.mq5"
//
// Include Classes ...
#include "../Classes/x-saherelm.class.lib.mq5"
//
input group "XUSCHF5 Provider";
//
// Commonly Used Configurations ...
input group "XUSCHF5 Common";
//
// Provider ...
input bool xUSCHF5EnableProvider = true; // Enable Provider
input int xUSCHF5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
//
// Alerts ...
input bool xUSCHF5EnableAlerts = true; // Enable Events Alert
input bool xUSCHF5EnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xUSCHF5EnableDailyAlerts = false; // Send Alert on each new Day
input bool xUSCHF5EnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xUSCHF5EnableMonthlyAlerts = true; // Send Alert on each new Month
//
// Reports ...
input bool xUSCHF5EnableDailyReports = false; // Send Report on each new Day
input bool xUSCHF5EnableWeeklyReports = false; // Send Report on each new Week
input bool xUSCHF5EnableMonthlyReports = false; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
input group "XUSCHF5 Trader";
input int xUSCHF5MagicNumber = 16940562; // Trader MagicNumber
input int xUSCHF5Slippage = 10; // Trader Slippage
//
// Trades Management Configurations ...
input group "XUSCHF5 Trade Management";
input bool xUSCHF5AllowLongTrades = true; // Allow Long Trades
input bool xUSCHF5AllowShortTrades = true; // Allow Short Trades
//
// Risk Management Configurations ...
input group "XUSCHF5 Risk Management";
//
// Trade Count ...
input int xUSCHF5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
input ENUM_X_CROSS_SIGNAL_METHOD xUSCHF5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xUSCHF5MaxAllowedTradeAge = 1500; // Detect Long Time Trades
input ENUM_X_GUARD_ACTIONS xUSCHF5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
input double xUSCHF5StaticVolumeFactor = 0.0001; // Static Volume baesd on Balance
input ENUM_STATIC_VOLUME_METHODS xUSCHF5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
input double xUSCHF5VolumeMultiplier = 0; // Volume Increase Multiplier
input double xUSCHF5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
input double xUSCHF5MaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
input double xUSCHF5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
//
// Trade Profits ...
input double xUSCHF5MinRewardInPips = 6; // Minimum Reward Per Trade in Pips
input double xUSCHF5RiskFreeStepInPips = 0; // Make Trades Risk Free Steps in Pips
input double xUSCHF5RiskFreeRate = 0; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xUSCHF5CriticalDrawDownFactor = 0.15; // Critical Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xUSCHF5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // Specify Guard Action on Critical Drawdown
input double xUSCHF5MaxAllowedDrawDownFactor = 0.20; // Max Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xUSCHF5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Max Allowed Drawdown
input int xUSCHF5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
//
// Account Conditions for Trading ...
input double xUSCHF5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
input double xUSCHF5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
//
// May be Used Later as Input Params ...
bool xUSCHF5UseVirtualTPSl = false; // Use Virtual TP SL
bool xUSCHF5EnableSignalAlerts = false; // Send Signal Alert
//
// Validate Inputs before Initialization ...
bool XUSCHF5ValidateInputs()
{
//
bool result = false;
//
// Implement Other Verifications ...
//
// Check Trading Availability ...
bool isTradeAvailable = xUSCHF5AllowLongTrades || xUSCHF5AllowShortTrades;
if (!isTradeAvailable)
{
LogMessage("XUSCHF5 => Warning: Trading disabled ...");
}
//
// Chekc Number of reading items per tick ...
result = xUSCHF5NumberOfItemsPerTick >= 5;
if (!result)
{
//
LogMessage("XUSCHF5 invalid Number of items Reading Per Tick ...");
//
return result;
}
//
// Check Max Allowed Trades Count ...
result = isTradeAvailable && xUSCHF5MaxAllowedTrades >= 1;
if (!result)
{
//
LogMessage("XUSCHF5 Number of Trades not valid ...");
//
return result;
}
//
// Check Free Margin ...
result =
isTradeAvailable &&
xUSCHF5FreeMarginFactorForOpenTrades > 0 &&
xUSCHF5FreeMarginFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Free Margin ...");
//
return result;
}
//
// Check min Balance for Open Trades ...
result =
isTradeAvailable &&
xUSCHF5BalanceFactorForOpenTrades > 0 &&
xUSCHF5BalanceFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Min Balance for Open Trades ...");
//
return result;
}
//
// Check Min Reward Per Trade ...
result = xUSCHF5MinRewardInPips > 0;
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Min Reward Per Trade ...");
//
return result;
}
//
// Check Trades Volume ...
result = xUSCHF5StaticVolumeFactor > 0;
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Static Volume ...");
//
return result;
}
//
// Check Volume Multiplier ...
result = xUSCHF5VolumeMultiplier >= 0;
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Volume Multiplier ...");
//
return result;
}
//
result =
xUSCHF5CriticalDrawDownFactor == 0 || (xUSCHF5CriticalDrawDownFactor > 0 &&
xUSCHF5CriticalDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Critical DrawDown Factor ...");
//
return result;
}
//
result =
xUSCHF5MaxAllowedDrawDownFactor == 0 || (xUSCHF5MaxAllowedDrawDownFactor > 0 &&
xUSCHF5MaxAllowedDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XUSCHF5 Invalid Max Allowed DrawDown Factor ...");
//
return result;
}
//
// Check Guard Actions ...
//
result =
xUSCHF5CriticalDrawDownFactor > 0 &&
xUSCHF5CriticalDrawDownFactor < 1 &&
xUSCHF5MaxAllowedDrawDownFactor > 0 &&
xUSCHF5MaxAllowedDrawDownFactor < 1;
if (!result)
{
//
LogMessage("XUSCHF5 For Critical Drawdown, you have to Specify Max Drawdown also ...");
//
return result;
}
//
result = xUSCHF5CriticalDrawDownFactor > 0 && xUSCHF5CriticalDrawDownFactor < xUSCHF5MaxAllowedDrawDownFactor;
if (!result)
{
//
LogMessage("XUSCHF5 Critical Drawdown must Smaller than Max Drawdown ...");
//
return result;
}
//
if (xUSCHF5CriticalDrawDownFactor > 0 && xUSCHF5CriticalGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XUSCHF5 IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
}
//
if (xUSCHF5MaxAllowedDrawDownFactor > 0 && xUSCHF5MaxAllowedGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XUSCHF5 IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
}
//
result = true;
//
return result;
}