Files
xMQL5/BKPS/14021004 XEU5/Providers/x-saherelm.xeu5.provider.inputs.lib.mq5
T
2024-01-25 04:09:42 +03:30

335 lines
9.8 KiB
Plaintext

///////////////////////////////////////////////////////////////
//
// 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";
//
// START Definitions ...
//
//
// the Action which Guard Handler Can Done when Attacked ...
enum ENUM_XEU5_GUARD_ACTIONS
{
//
// Do Nothing ...
XEU5_GUARD_DO_NOTHING,
//
// Close All Open Positions ...
XEU5_GUARD_CLOSE_ALL,
//
// Close Max In Drawdown Position ...
XEU5_GUARD_CLOSE_MAX_IN_DD,
//
// Partial Close Max In Drawdown Position by 5% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5,
//
// Partial Close Max In Drawdown Position by 10% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_10,
//
// Partial Close Max In Drawdown Position by 25% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_25,
//
// Partial Close Max In Drawdown Position by 30% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_30,
//
// Partial Close Max In Drawdown Position by 40% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_40,
//
// Partial Close Max In Drawdown Position by 50% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_50,
//
// Partial Close Max In Drawdown Position by 60% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_60,
//
// Partial Close Max In Drawdown Position by 75% of Volume ...
XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_75,
};
//
// How To Calculate Static Volume ...
enum ENUM_XEU5_STATIC_VOLUME_METHODS
{
//
// Based On Deposit ...
XEU5_STATIC_VOLUME_BASED_ON_DEPOSIT,
//
// Based On Balance ...
XEU5_STATIC_VOLUME_BASED_ON_BALANCE,
};
//
// Cross Signals Methods ...
enum ENUM_XEU5_CROSS_SIGNAL_METHOD
{
//
// Do Nothing and Ignore them ...
XEU5_CROSS_SIGNAL_DO_NOTHING,
//
// Accept all Cross Signals and Act Usually ...
XEU5_CROSS_SIGNAL_REGULAR,
//
// Accept all Cross Signals and for Directional Act Usually and for Indirectional Ac Important ...
XEU5_CROSS_SIGNAL_DIRECTION_REGULAR_INDIRECTION_IMPORTANT,
//
// Accept all Cross Signals and for Directional Act Important and for Indirectional Ac Usually ...
XEU5_CROSS_SIGNAL_DIRECTION_IMPORTANT_INDIRECTION_REGULAR,
//
// Accept Only Indirectional Signals and Act Usually ...
XEU5_CROSS_SIGNAL_INDIRECTION_REGULAR,
//
// Accept Only Directional Signals and Act Usually ...
XEU5_CROSS_SIGNAL_DIRECTION_REGULAR,
//
// Accept Only Indirectional Signals and Act Important ...
XEU5_CROSS_SIGNAL_INDIRECTION_IMPORTANT,
//
// Accept Only Directional Signals and Act Important ...
XEU5_CROSS_SIGNAL_DIRECTION_IMPORTANT,
};
//
// Too Old Signals Method ...
enum ENUM_XEU5_TOO_OLD_SIGNAL_ACTIONS
{
//
// Ignore and do nothing ...
XEU5_TOO_OLD_IGNORE,
//
// Close Too Old Signal ...
XEU5_TOO_OLD_CLOSE,
//
// Close Too Old Signal If In Profit ...
XEU5_TOO_OLD_CLOSE_IN_PROFIT,
//
// Close Too Old Signal If In Drawdown ...
XEU5_TOO_OLD_CLOSE_IN_DRAWDOWN,
//
// Partial Close Too Old Signal by 0.01 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_01,
//
// Partial Close Too Old Signal by 0.05 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_05,
//
// Partial Close Too Old Signal by 0.1 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_10,
//
// Partial Close Too Old Signal by 0.2 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_20,
//
// Partial Close Too Old Signal by 0.25 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_25,
//
// Partial Close Too Old Signal by 0.30 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_30,
//
// Partial Close Too Old Signal by 0.50 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_50,
//
// Partial Close Too Old Signal by 0.75 ...
XEU5_TOO_OLD_PARTIAL_CLOSE_75,
};
//
// END Definitions ...
//
//
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 = true; // 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 = true; // Send Report on each new Month
//
// Trader and Expert Specific Configurations ...
input group "XEU5 Trader";
input int xEU5MagicNumber = 16940561; // 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 = 4; // Max Allowed Trades at Same Time
input ENUM_XEU5_CROSS_SIGNAL_METHOD xEU5CrossSignalsMethod = XEU5_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
//
// Max Allowed Trade Age ...
input int xEU5MaxAllowedTradeAge = 0; // Detect Long Time Trades
input ENUM_XEU5_TOO_OLD_SIGNAL_ACTIONS xEU5OldTradesAction = XEU5_TOO_OLD_IGNORE; // What to do with Old Trades
//
// Trade Volume Specific Configurations ...
input double xEU5StaticVolumeFactor = 0.00002; // Static Volume baesd on Balance
input ENUM_XEU5_STATIC_VOLUME_METHODS xEU5StaticVolumeMethod = XEU5_STATIC_VOLUME_BASED_ON_DEPOSIT; // How to Calculate Static Volume
input double xEU5VolumeMultiplier = 2.0; // Volume Increase Multiplier
input double xEU5ApplyVolumeMultiplierFactor = 0.002; // Apply Volume Multiplier Rate based on Balance
input double xEU5MaxSupportedVolumePerTradeFactor = 0.00008; // Max Supported Volume Per Trade Factor based on Balance
input double xEU5IncreasedMaxSupportedVolumeRate = 0.3; // Increase Max Supported Volume based on Balance
//
// Trade Profits ...
input double xEU5MinRewardInPips = 15; // Minimum Reward Per Trade in Pips
input double xEU5RiskFreeStepInPips = 4; // Make Trades Risk Free Steps in Pips
input double xEU5RiskFreeRate = 0.75; // Volume Multiplier for Risk Free Trades
//
// Guard Riskable Money and Profits ...
input double xEU5MaxAllowedRiskOnTradesFactor = 0.25; // Max Allowed Trades Drawdown based on Balance
input ENUM_XEU5_GUARD_ACTIONS xEU5GuardAction = XEU5_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Action when Max Allowed Drawdown Reached
//
// 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
//
// 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 = true;
//
return result;
}