last works ...

This commit is contained in:
2025-09-10 21:02:38 +03:30
parent 4d50472a0c
commit a3016b0c63
6 changed files with 515 additions and 118 deletions
+174
View File
@@ -375,6 +375,56 @@ ENUM_XTRADE_RESTRICTION_PERIOD ToXRestrictionPeriod(string value)
return result;
}
//
int GetXRestrictionsPeriodSeconds(ENUM_XTRADE_RESTRICTION_PERIOD value)
{
//
int result = 0;
//
if (!HasRestrictions(value))
{
return result;
}
//
switch (value)
{
//
// None ...
case XTRADE_RESTRICATION_NONE:
result = 0;
break;
//
// Hour ...
case XTRADE_RESTRICATION_HOURLY:
result = PeriodSeconds(PERIOD_H1);
break;
//
// Dayly ...
case XTRADE_RESTRICATION_DAILY:
result = PeriodSeconds(PERIOD_D1);
break;
//
// Weekly ...
case XTRADE_RESTRICATION_WEEKLY:
result = PeriodSeconds(PERIOD_W1);
break;
//
// Monthly ...
case XTRADE_RESTRICATION_MONTHLY:
result = PeriodSeconds(PERIOD_M1);
break;
}
//
return result;
}
/**
* Check a Value Has Trade Restrictions or not ...
*
@@ -3049,6 +3099,68 @@ struct XSymbolTradeConfig
return result;
}
//
// Checking Restrictions ...
bool IsRestricted(datetime time = NULL)
{
//
bool result = false;
//
// Normalize Time ...
time = NormalizeTime(time);
//
// Check Has Restrictions ...
bool has = HasRestrictions(restrictionsPeriod);
result = !has;
if (result)
{
return result;
}
//
// Check Restrictions Time ...
has = IsSpecifiedValid(managedStart) &&
time <= managedStart;
result = !has;
if (result)
{
return result;
}
//
// Validate Restrictions Timing ...
// Check Restrictions ...
//
bool isTPAllowed = maxAllowedTPs == 0
? true
: managedTPs < maxAllowedTPs;
bool isSLAllowed = maxAllowedSLs == 0
? true
: managedSLs < maxAllowedSLs;
bool isTradeAllowed = maxAllowedTrades == 0
? true
: managedTrades < maxAllowedTrades;
//
result = isTPAllowed &&
isSLAllowed &&
isTradeAllowed;
if (result)
{
return result;
}
//
// Check Restrictions Reset ...
HandleRestrictions();
//
return result;
}
//
// Parse Sessions ...
void ParseSessions(string descriptor)
@@ -3244,6 +3356,61 @@ struct XSymbolTradeConfig
restrictionsPeriod = XTRADE_RESTRICATION_NONE;
}
//
// Handle Restrictions ...
void HandleRestrictions(datetime time = NULL)
{
//
// Normalize Time ...
time = NormalizeTime(time);
//
// Check Restrictions Requirements ...
bool has = HasRestrictions(restrictionsPeriod) &&
restrictionsPeriodMultiplier >= 1;
if (!has)
{
return;
}
//
// Check Restrictions Start ...
has = IsSpecifiedValid(managedStart);
if (!has)
{
managedStart = time;
}
//
// Calculating Expiration Date based on Config ...
int expiredDelay = restrictionsPeriodMultiplier * GetXRestrictionsPeriodSeconds(restrictionsPeriod);
datetime expiredDate = (datetime)(TimeToSeconds(managedStart) + expiredDelay);
//
// Check Expiration ...
has = time >= expiredDate;
if (!has)
{
return;
}
//
ResetRestrictions();
}
//
// Reset Restrictions ...
void ResetRestrictions()
{
//
managedSLs = 0;
managedTPs = 0;
managedTrades = 0;
managedBalance = 0;
managedProfits = 0;
managedStart = TimeCurrent();
}
//
};
@@ -3576,6 +3743,13 @@ struct XTradeInfo
//
typedef void (*TOnSignal)(XSignal &signal);
//
typedef bool (*TCanAnalyse)(
string _symbol,
ENUM_TIMEFRAMES _period,
datetime _time //
);
//
typedef void (*TOnDealsChanged)(int count);