refactor for xTestEa all Workspace and Cleanup Providers Market Conditions ...

This commit is contained in:
2024-03-25 03:13:16 +03:30
parent f7061cde0f
commit fa4c3098a9
6 changed files with 2695 additions and 7047 deletions
File diff suppressed because it is too large Load Diff
@@ -1,283 +0,0 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XBTUS5 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 "XBTUS5 Provider";
//
// Commonly Used Configurations ...
input group "XBTUS5 Common";
//
// Provider ...
input bool xBTUS5EnableProvider = true; // Enable Provider
input int xBTUS5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
//
// Alerts ...
input bool xBTUS5EnableAlerts = true; // Enable Events Alert
input bool xBTUS5EnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xBTUS5EnableDailyAlerts = false; // Send Alert on each new Day
input bool xBTUS5EnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xBTUS5EnableMonthlyAlerts = false; // Send Alert on each new Month
//
// Reports ...
input bool xBTUS5EnableDailyReports = false; // Send Report on each new Day
input bool xBTUS5EnableWeeklyReports = false; // Send Report on each new Week
input bool xBTUS5EnableMonthlyReports = false; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
input group "XBTUS5 Trader";
input int xBTUS5MagicNumber = 16940563; // Trader MagicNumber
input int xBTUS5Slippage = 10; // Trader Slippage
//
// Trades Management Configurations ...
input group "XBTUS5 Trade Management";
input bool xBTUS5AllowLongTrades = true; // Allow Long Trades
input bool xBTUS5AllowShortTrades = true; // Allow Short Trades
//
// Risk Management Configurations ...
input group "XBTUS5 Risk Management";
//
// Trade Count ...
input int xBTUS5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
input ENUM_X_CROSS_SIGNAL_METHOD xBTUS5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xBTUS5MaxAllowedTradeAge = 1500; // Detect Long Time Trades
input ENUM_X_GUARD_ACTIONS xBTUS5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
input double xBTUS5StaticVolumeFactor = 0.0001; // Static Volume baesd on Balance
input ENUM_STATIC_VOLUME_METHODS xBTUS5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
input double xBTUS5VolumeMultiplier = 0; // Volume Increase Multiplier
input double xBTUS5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
input double xBTUS5MaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
input double xBTUS5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
//
// Trade Profits ...
input double xBTUS5MinRewardInPips = 60; // Minimum Reward Per Trade in Pips
input double xBTUS5RiskFreeStepInPips = 0; // Make Trades Risk Free Steps in Pips
input double xBTUS5RiskFreeRate = 0; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xBTUS5CriticalDrawDownFactor = 0.30; // Critical Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xBTUS5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // Specify Guard Action on Critical Drawdown
input double xBTUS5MaxAllowedDrawDownFactor = 0.40; // Max Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xBTUS5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Max Allowed Drawdown
input int xBTUS5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
//
// Account Conditions for Trading ...
input double xBTUS5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
input double xBTUS5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
//
// May be Used Later as Input Params ...
bool xBTUS5UseVirtualTPSl = false; // Use Virtual TP SL
bool xBTUS5EnableSignalAlerts = false; // Send Signal Alert
//
// Validate Inputs before Initialization ...
bool XBTUS5ValidateInputs()
{
//
bool result = false;
//
// Implement Other Verifications ...
//
// Check Trading Availability ...
bool isTradeAvailable = xBTUS5AllowLongTrades || xBTUS5AllowShortTrades;
if (!isTradeAvailable)
{
LogMessage("XBTUS5 => Warning: Trading disabled ...");
}
//
// Chekc Number of reading items per tick ...
result = xBTUS5NumberOfItemsPerTick >= 5;
if (!result)
{
//
LogMessage("XBTUS5 invalid Number of items Reading Per Tick ...");
//
return result;
}
//
// Check Max Allowed Trades Count ...
result = isTradeAvailable && xBTUS5MaxAllowedTrades >= 1;
if (!result)
{
//
LogMessage("XBTUS5 Number of Trades not valid ...");
//
return result;
}
//
// Check Free Margin ...
result =
isTradeAvailable &&
xBTUS5FreeMarginFactorForOpenTrades > 0 &&
xBTUS5FreeMarginFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XBTUS5 Invalid Free Margin ...");
//
return result;
}
//
// Check min Balance for Open Trades ...
result =
isTradeAvailable &&
xBTUS5BalanceFactorForOpenTrades > 0 &&
xBTUS5BalanceFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XBTUS5 Invalid Min Balance for Open Trades ...");
//
return result;
}
//
// Check Min Reward Per Trade ...
result = xBTUS5MinRewardInPips > 0;
if (!result)
{
//
LogMessage("XBTUS5 Invalid Min Reward Per Trade ...");
//
return result;
}
//
// Check Trades Volume ...
result = xBTUS5StaticVolumeFactor > 0;
if (!result)
{
//
LogMessage("XBTUS5 Invalid Static Volume ...");
//
return result;
}
//
// Check Volume Multiplier ...
result = xBTUS5VolumeMultiplier >= 0;
if (!result)
{
//
LogMessage("XBTUS5 Invalid Volume Multiplier ...");
//
return result;
}
//
result =
xBTUS5CriticalDrawDownFactor == 0 || (xBTUS5CriticalDrawDownFactor > 0 &&
xBTUS5CriticalDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XBTUS5 Invalid Critical DrawDown Factor ...");
//
return result;
}
//
result =
xBTUS5MaxAllowedDrawDownFactor == 0 || (xBTUS5MaxAllowedDrawDownFactor > 0 &&
xBTUS5MaxAllowedDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XBTUS5 Invalid Max Allowed DrawDown Factor ...");
//
return result;
}
//
// Check Guard Actions ...
//
result =
xBTUS5CriticalDrawDownFactor > 0 &&
xBTUS5CriticalDrawDownFactor < 1 &&
xBTUS5MaxAllowedDrawDownFactor > 0 &&
xBTUS5MaxAllowedDrawDownFactor < 1;
if (!result)
{
//
LogMessage("XBTUS5 For Critical Drawdown, you have to Specify Max Drawdown also ...");
//
return result;
}
//
result = xBTUS5CriticalDrawDownFactor > 0 && xBTUS5CriticalDrawDownFactor < xBTUS5MaxAllowedDrawDownFactor;
if (!result)
{
//
LogMessage("XBTUS5 Critical Drawdown must Smaller than Max Drawdown ...");
//
return result;
}
//
if (xBTUS5CriticalDrawDownFactor > 0 && xBTUS5CriticalGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XBTUS5 IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
}
//
if (xBTUS5MaxAllowedDrawDownFactor > 0 && xBTUS5MaxAllowedGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XBTUS5 IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
}
//
result = true;
//
return result;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,283 @@
///////////////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 XTEST 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 "XTEST Provider";
//
// Commonly Used Configurations ...
input group "XTEST Common";
//
// Provider ...
input bool xTESTEnableProvider = true; // Enable Provider
input int xTESTNumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
//
// Alerts ...
input bool xTESTEnableAlerts = true; // Enable Events Alert
input bool xTESTEnableHourlyAlerts = false; // Send Alert on each new Hour
input bool xTESTEnableDailyAlerts = false; // Send Alert on each new Day
input bool xTESTEnableWeeklyAlerts = false; // Send Alert on each new Week
input bool xTESTEnableMonthlyAlerts = false; // Send Alert on each new Month
//
// Reports ...
input bool xTESTEnableDailyReports = false; // Send Report on each new Day
input bool xTESTEnableWeeklyReports = false; // Send Report on each new Week
input bool xTESTEnableMonthlyReports = false; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
input group "XTEST Trader";
input int xTESTMagicNumber = 16940563; // Trader MagicNumber
input int xTESTSlippage = 10; // Trader Slippage
//
// Trades Management Configurations ...
input group "XTEST Trade Management";
input bool xTESTAllowLongTrades = true; // Allow Long Trades
input bool xTESTAllowShortTrades = true; // Allow Short Trades
//
// Risk Management Configurations ...
input group "XTEST Risk Management";
//
// Trade Count ...
input int xTESTMaxAllowedTrades = 10; // Max Allowed Trades at Same Time
input ENUM_X_CROSS_SIGNAL_METHOD xTESTCrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xTESTMaxAllowedTradeAge = 1500; // Detect Long Time Trades
input ENUM_X_GUARD_ACTIONS xTESTOldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
input double xTESTStaticVolumeFactor = 0.0001; // Static Volume baesd on Balance
input ENUM_STATIC_VOLUME_METHODS xTESTStaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
input double xTESTVolumeMultiplier = 0; // Volume Increase Multiplier
input double xTESTApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
input double xTESTMaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
input double xTESTIncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
//
// Trade Profits ...
input double xTESTMinRewardInPips = 60; // Minimum Reward Per Trade in Pips
input double xTESTRiskFreeStepInPips = 0; // Make Trades Risk Free Steps in Pips
input double xTESTRiskFreeRate = 0; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xTESTCriticalDrawDownFactor = 0.30; // Critical Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xTESTCriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // Specify Guard Action on Critical Drawdown
input double xTESTMaxAllowedDrawDownFactor = 0.40; // Max Allowed Drawdown Factor based on Balance
input ENUM_X_GUARD_ACTIONS xTESTMaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Max Allowed Drawdown
input int xTESTGuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
//
// Account Conditions for Trading ...
input double xTESTBalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
input double xTESTFreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
//
// May be Used Later as Input Params ...
bool xTESTUseVirtualTPSl = false; // Use Virtual TP SL
bool xTESTEnableSignalAlerts = false; // Send Signal Alert
//
// Validate Inputs before Initialization ...
bool XTESTValidateInputs()
{
//
bool result = false;
//
// Implement Other Verifications ...
//
// Check Trading Availability ...
bool isTradeAvailable = xTESTAllowLongTrades || xTESTAllowShortTrades;
if (!isTradeAvailable)
{
LogMessage("XTEST => Warning: Trading disabled ...");
}
//
// Chekc Number of reading items per tick ...
result = xTESTNumberOfItemsPerTick >= 5;
if (!result)
{
//
LogMessage("XTEST invalid Number of items Reading Per Tick ...");
//
return result;
}
//
// Check Max Allowed Trades Count ...
result = isTradeAvailable && xTESTMaxAllowedTrades >= 1;
if (!result)
{
//
LogMessage("XTEST Number of Trades not valid ...");
//
return result;
}
//
// Check Free Margin ...
result =
isTradeAvailable &&
xTESTFreeMarginFactorForOpenTrades > 0 &&
xTESTFreeMarginFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XTEST Invalid Free Margin ...");
//
return result;
}
//
// Check min Balance for Open Trades ...
result =
isTradeAvailable &&
xTESTBalanceFactorForOpenTrades > 0 &&
xTESTBalanceFactorForOpenTrades < 1;
if (!result)
{
//
LogMessage("XTEST Invalid Min Balance for Open Trades ...");
//
return result;
}
//
// Check Min Reward Per Trade ...
result = xTESTMinRewardInPips > 0;
if (!result)
{
//
LogMessage("XTEST Invalid Min Reward Per Trade ...");
//
return result;
}
//
// Check Trades Volume ...
result = xTESTStaticVolumeFactor > 0;
if (!result)
{
//
LogMessage("XTEST Invalid Static Volume ...");
//
return result;
}
//
// Check Volume Multiplier ...
result = xTESTVolumeMultiplier >= 0;
if (!result)
{
//
LogMessage("XTEST Invalid Volume Multiplier ...");
//
return result;
}
//
result =
xTESTCriticalDrawDownFactor == 0 || (xTESTCriticalDrawDownFactor > 0 &&
xTESTCriticalDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XTEST Invalid Critical DrawDown Factor ...");
//
return result;
}
//
result =
xTESTMaxAllowedDrawDownFactor == 0 || (xTESTMaxAllowedDrawDownFactor > 0 &&
xTESTMaxAllowedDrawDownFactor < 1);
if (!result)
{
//
LogMessage("XTEST Invalid Max Allowed DrawDown Factor ...");
//
return result;
}
//
// Check Guard Actions ...
//
result =
xTESTCriticalDrawDownFactor > 0 &&
xTESTCriticalDrawDownFactor < 1 &&
xTESTMaxAllowedDrawDownFactor > 0 &&
xTESTMaxAllowedDrawDownFactor < 1;
if (!result)
{
//
LogMessage("XTEST For Critical Drawdown, you have to Specify Max Drawdown also ...");
//
return result;
}
//
result = xTESTCriticalDrawDownFactor > 0 && xTESTCriticalDrawDownFactor < xTESTMaxAllowedDrawDownFactor;
if (!result)
{
//
LogMessage("XTEST Critical Drawdown must Smaller than Max Drawdown ...");
//
return result;
}
//
if (xTESTCriticalDrawDownFactor > 0 && xTESTCriticalGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XTEST IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
}
//
if (xTESTMaxAllowedDrawDownFactor > 0 && xTESTMaxAllowedGuardAction == X_GUARD_DO_NOTHING)
{
LogMessage("XTEST IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
}
//
result = true;
//
return result;
}