280 lines
8.5 KiB
Plaintext
280 lines
8.5 KiB
Plaintext
///////////////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 XBTU5 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 "XBTU5 Provider";
|
|
|
|
//
|
|
// Commonly Used Configurations ...
|
|
input group "XBTU5 Common";
|
|
//
|
|
// Provider ...
|
|
input bool xBTU5EnableProvider = true; // Enable Provider
|
|
input int xBTU5NumberOfItemsPerTick = 30; // Number Of items Readed In Each Tick
|
|
//
|
|
// Alerts ...
|
|
input bool xBTU5EnableAlerts = true; // Enable Events Alert
|
|
input bool xBTU5EnableHourlyAlerts = false; // Send Alert on each new Hour
|
|
input bool xBTU5EnableDailyAlerts = false; // Send Alert on each new Day
|
|
input bool xBTU5EnableWeeklyAlerts = false; // Send Alert on each new Week
|
|
input bool xBTU5EnableMonthlyAlerts = true; // Send Alert on each new Month
|
|
//
|
|
// Reports ...
|
|
input bool xBTU5EnableDailyReports = false; // Send Report on each new Day
|
|
input bool xBTU5EnableWeeklyReports = false; // Send Report on each new Week
|
|
input bool xBTU5EnableMonthlyReports = true; // Send Report on each new Month
|
|
|
|
//
|
|
// Trader and Expert Specific Configurations ...
|
|
input group "XBTU5 Trader";
|
|
input int xBTU5MagicNumber = 16940560; // Trader MagicNumber
|
|
input int xBTU5Slippage = 10; // Trader Slippage
|
|
|
|
//
|
|
// Trades Management Configurations ...
|
|
input group "XBTU5 Trade Management";
|
|
input bool xBTU5AllowLongTrades = true; // Allow Long Trades
|
|
input bool xBTU5AllowShortTrades = true; // Allow Short Trades
|
|
|
|
//
|
|
// Risk Management Configurations ...
|
|
input group "XBTU5 Risk Management";
|
|
//
|
|
input bool xBTU5UseVirtualTPSl = true; // Use Virtual TP SL
|
|
//
|
|
// Trade Count ...
|
|
input int xBTU5MaxAllowedTrades = 10; // Max Allowed Trades at Same Time
|
|
input ENUM_X_CROSS_SIGNAL_METHOD xBTU5CrossSignalsMethod = X_CROSS_SIGNAL_REGULAR; // Handle Cross Signals Method
|
|
//
|
|
// Max Allowed Trade Age ...
|
|
input int xBTU5MaxAllowedTradeAge = 2000; // Detect Long Time Trades
|
|
input ENUM_X_GUARD_ACTIONS xBTU5OldTradesAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_1; // What to do with Old Trades
|
|
//
|
|
// Trade Volume Specific Configurations ...
|
|
input double xBTU5StaticVolumeFactor = 0.0002; // Static Volume baesd on Balance
|
|
input ENUM_STATIC_VOLUME_METHODS xBTU5StaticVolumeMethod = X_STATIC_VOLUME_BASED_ON_BALANCE; // How to Calculate Static Volume
|
|
input double xBTU5VolumeMultiplier = 0; // Volume Increase Multiplier
|
|
input double xBTU5ApplyVolumeMultiplierFactor = 0; // Apply Volume Multiplier Rate based on Balance
|
|
input double xBTU5MaxSupportedVolumePerTradeFactor = 0; // Max Supported Volume Per Trade Factor based on Balance
|
|
input double xBTU5IncreasedMaxSupportedVolumeRate = 0; // Increase Max Supported Volume based on Balance
|
|
//
|
|
// Trade Profits ...
|
|
input double xBTU5MinRewardInPips = 15; // Minimum Reward Per Trade in Pips
|
|
input double xBTU5RiskFreeStepInPips = 6; // Make Trades Risk Free Steps in Pips
|
|
input double xBTU5RiskFreeRate = 0.6; // Volume Multiplier for Risk Free Trades
|
|
//
|
|
// Guard Riskable Money and Profits ...
|
|
input double xBTU5CriticalDrawDownFactor = 0.43; // Critical Allowed Drawdown Factor based on Balance
|
|
input ENUM_X_GUARD_ACTIONS xBTU5CriticalGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_5; // Specify Guard Action on Critical Drawdown
|
|
input double xBTU5MaxAllowedDrawDownFactor = 0.45; // Max Allowed Drawdown Factor based on Balance
|
|
input ENUM_X_GUARD_ACTIONS xBTU5MaxAllowedGuardAction = X_GUARD_PARTIAL_CLOSE_MAX_IN_DD_10; // Specify Guard Action on Max Allowed Drawdown
|
|
input int xBTU5GuardStopoutFiredAfterTouches = 5; // Guard Stopout all Trades if Max Allowed Drawdown touched
|
|
|
|
//
|
|
// Account Conditions for Trading ...
|
|
input double xBTU5BalanceFactorForOpenTrades = 0.5; // Minimum Balance for Open Trades
|
|
input double xBTU5FreeMarginFactorForOpenTrades = 0.8; // Minimum Free Margin for Open Trades
|
|
|
|
//
|
|
// Validate Inputs before Initialization ...
|
|
bool XBTU5ValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Implement Other Verifications ...
|
|
|
|
//
|
|
// Check Trading Availability ...
|
|
bool isTradeAvailable = xBTU5AllowLongTrades || xBTU5AllowShortTrades;
|
|
if (!isTradeAvailable)
|
|
{
|
|
LogMessage("XBTU5 => Warning: Trading disabled ...");
|
|
}
|
|
|
|
//
|
|
// Chekc Number of reading items per tick ...
|
|
result = xBTU5NumberOfItemsPerTick >= 5;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 invalid Number of items Reading Per Tick ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Max Allowed Trades Count ...
|
|
result = isTradeAvailable && xBTU5MaxAllowedTrades >= 1;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Number of Trades not valid ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Free Margin ...
|
|
result =
|
|
isTradeAvailable &&
|
|
xBTU5FreeMarginFactorForOpenTrades > 0 &&
|
|
xBTU5FreeMarginFactorForOpenTrades < 1;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Free Margin ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check min Balance for Open Trades ...
|
|
result =
|
|
isTradeAvailable &&
|
|
xBTU5BalanceFactorForOpenTrades > 0 &&
|
|
xBTU5BalanceFactorForOpenTrades < 1;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Min Balance for Open Trades ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Min Reward Per Trade ...
|
|
result = xBTU5MinRewardInPips > 0;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Min Reward Per Trade ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Trades Volume ...
|
|
result = xBTU5StaticVolumeFactor > 0;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Static Volume ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Volume Multiplier ...
|
|
result = xBTU5VolumeMultiplier >= 0;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Volume Multiplier ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
xBTU5CriticalDrawDownFactor == 0 || (xBTU5CriticalDrawDownFactor > 0 &&
|
|
xBTU5CriticalDrawDownFactor < 1);
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Critical DrawDown Factor ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
xBTU5MaxAllowedDrawDownFactor == 0 || (xBTU5MaxAllowedDrawDownFactor > 0 &&
|
|
xBTU5MaxAllowedDrawDownFactor < 1);
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Invalid Max Allowed DrawDown Factor ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Check Guard Actions ...
|
|
//
|
|
result =
|
|
xBTU5CriticalDrawDownFactor > 0 &&
|
|
xBTU5CriticalDrawDownFactor < 1 &&
|
|
xBTU5MaxAllowedDrawDownFactor > 0 &&
|
|
xBTU5MaxAllowedDrawDownFactor < 1;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 For Critical Drawdown, you have to Specify Max Drawdown also ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = xBTU5CriticalDrawDownFactor > 0 && xBTU5CriticalDrawDownFactor < xBTU5MaxAllowedDrawDownFactor;
|
|
if (!result)
|
|
{
|
|
//
|
|
LogMessage("XBTU5 Critical Drawdown must Smaller than Max Drawdown ...");
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (xBTU5CriticalDrawDownFactor > 0 && xBTU5CriticalGuardAction == X_GUARD_DO_NOTHING)
|
|
{
|
|
LogMessage("XBTU5 IMPORTANT you Specified Critical Drawdown, but there is no any Guard Action ...");
|
|
}
|
|
|
|
//
|
|
if (xBTU5MaxAllowedDrawDownFactor > 0 && xBTU5MaxAllowedGuardAction == X_GUARD_DO_NOTHING)
|
|
{
|
|
LogMessage("XBTU5 IMPORTANT you Specified Max Allowed Drawdown, but there is no any Guard Action ...");
|
|
}
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
} |