last ...
This commit is contained in:
@@ -318,7 +318,61 @@ enum ENUM_XTRADE_RESTRICTION_PERIOD
|
||||
//
|
||||
string ToXString(ENUM_XTRADE_RESTRICTION_PERIOD value)
|
||||
{
|
||||
return EnumToString(value);
|
||||
//
|
||||
string result = NULL;
|
||||
|
||||
//
|
||||
result = EnumToString(value);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_XTRADE_RESTRICTION_PERIOD ToXRestrictionPeriod(string value)
|
||||
{
|
||||
//
|
||||
ENUM_XTRADE_RESTRICTION_PERIOD result = XTRADE_RESTRICATION_NONE;
|
||||
|
||||
//
|
||||
if (!IsSpecifiedValid(value))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// None ...
|
||||
if (value == ToXString(XTRADE_RESTRICATION_NONE))
|
||||
{
|
||||
result = XTRADE_RESTRICATION_NONE;
|
||||
}
|
||||
//
|
||||
// Per Hour ...
|
||||
else if (value == ToXString(XTRADE_RESTRICATION_HOURLY))
|
||||
{
|
||||
result = XTRADE_RESTRICATION_HOURLY;
|
||||
}
|
||||
//
|
||||
// Per Day ...
|
||||
else if (value == ToXString(XTRADE_RESTRICATION_DAILY))
|
||||
{
|
||||
result = XTRADE_RESTRICATION_DAILY;
|
||||
}
|
||||
//
|
||||
// Per Week ...
|
||||
else if (value == ToXString(XTRADE_RESTRICATION_WEEKLY))
|
||||
{
|
||||
result = XTRADE_RESTRICATION_WEEKLY;
|
||||
}
|
||||
//
|
||||
// Per Month ...
|
||||
else if (value == ToXString(XTRADE_RESTRICATION_MONTHLY))
|
||||
{
|
||||
result = XTRADE_RESTRICATION_MONTHLY;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2873,10 +2927,7 @@ struct XSymbolTradeConfig
|
||||
* @param _sessionsDescriptor: Sessions Description
|
||||
* @param _maxAllowedSpread: Max Allowed Spread for Open Trade
|
||||
* @param _maxAllowedPositions: Max Allowed Same Time Position
|
||||
* @param _closeAllOpenTradesAt: Close All Open Trades
|
||||
* @param _maxAllowedTPs: Max Allowed TPs in Restrictions Period
|
||||
* @param _maxAllowedSLs: Max Allowed SLs in Restrictions Period
|
||||
* @param _restrictionsPeriod: Restrictions Period
|
||||
* @param _restrictionsDescriptor: Restrictions Descriptor
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
@@ -2887,10 +2938,6 @@ struct XSymbolTradeConfig
|
||||
double _maxAllowedSpread = 25,
|
||||
int _maxAllowedPositions = 5,
|
||||
string _restrictionsDescriptor = NULL //
|
||||
// string _closeAllOpenTradesAt = NULL,
|
||||
// int _maxAllowedTPs = 0,
|
||||
// int _maxAllowedSLs = 0,
|
||||
// ENUM_XTRADE_RESTRICTION_PERIOD _restrictionsPeriod = XTRADE_RESTRICATION_NONE //
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -2907,12 +2954,6 @@ struct XSymbolTradeConfig
|
||||
maxAllowedSpread = _maxAllowedSpread;
|
||||
maxAllowedPositions = _maxAllowedPositions;
|
||||
|
||||
//
|
||||
// maxAllowedTPs = _maxAllowedTPs;
|
||||
// maxAllowedSLs = _maxAllowedSLs;
|
||||
// restrictionsPeriod = _restrictionsPeriod;
|
||||
// closeAllOpenTradesAt = _closeAllOpenTradesAt;
|
||||
|
||||
//
|
||||
// Parse Sessions ...
|
||||
ParseSessions(_sessionsDescriptor);
|
||||
@@ -2922,6 +2963,7 @@ struct XSymbolTradeConfig
|
||||
ParseRestrictions(_restrictionsDescriptor);
|
||||
|
||||
//
|
||||
// Check Validation ...
|
||||
result = IsValid();
|
||||
|
||||
//
|
||||
@@ -3011,6 +3053,7 @@ struct XSymbolTradeConfig
|
||||
void ParseSessions(string descriptor)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsSpecifiedValid(descriptor))
|
||||
{
|
||||
return;
|
||||
@@ -3098,8 +3141,98 @@ struct XSymbolTradeConfig
|
||||
|
||||
//
|
||||
// Parse Restrictions ...
|
||||
void ParseRestrictions(string descriptor) {
|
||||
|
||||
void ParseRestrictions(string descriptor)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsSpecifiedValid(descriptor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Content ...
|
||||
descriptor = ExtractString(descriptor);
|
||||
if (!IsSpecifiedValid(descriptor))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int count = 0;
|
||||
bool has = false;
|
||||
string iRestrictionsParts[];
|
||||
|
||||
//
|
||||
// Extract Parts ...
|
||||
count = SplitContent(
|
||||
iRestrictionsParts,
|
||||
descriptor,
|
||||
"," //
|
||||
);
|
||||
has = IsValidSize(count);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
// Default Restrictions ...
|
||||
ApplyDefaultRestrictions();
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Try To Extract Required Parts ...
|
||||
bool hasRestrictionsPeriod = count >= 1;
|
||||
bool hasMaxAllowedTPs = count >= 2;
|
||||
bool hasMaxAllowedSLs = count >= 3;
|
||||
bool hasMaxAllowedTrades = count >= 4;
|
||||
bool hasCloseAllOpenTradesAt = count >= 5;
|
||||
|
||||
//
|
||||
// Restrictions Period ...
|
||||
restrictionsPeriod =
|
||||
hasRestrictionsPeriod
|
||||
? ToXRestrictionPeriod(Trim(iRestrictionsParts[0]))
|
||||
: XTRADE_RESTRICATION_NONE;
|
||||
|
||||
//
|
||||
// Max Allowed TPs ...
|
||||
maxAllowedTPs =
|
||||
hasMaxAllowedTPs
|
||||
? (int)(Trim(iRestrictionsParts[1]))
|
||||
: 0;
|
||||
|
||||
//
|
||||
// Max Allowed SLs ...
|
||||
maxAllowedSLs =
|
||||
hasMaxAllowedSLs
|
||||
? (int)(Trim(iRestrictionsParts[2]))
|
||||
: 0;
|
||||
|
||||
//
|
||||
// Max Allowed Trades ...
|
||||
maxAllowedTrades =
|
||||
hasMaxAllowedTrades
|
||||
? (int)(Trim(iRestrictionsParts[3]))
|
||||
: 0;
|
||||
|
||||
//
|
||||
// Close All Open Trades At ...
|
||||
closeAllOpenTradesAt =
|
||||
hasCloseAllOpenTradesAt
|
||||
? Trim(iRestrictionsParts[4])
|
||||
: NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Apply Default Restrictions ...
|
||||
void ApplyDefaultRestrictions()
|
||||
{
|
||||
//
|
||||
maxAllowedTPs = 0;
|
||||
maxAllowedSLs = 0;
|
||||
maxAllowedTrades = 0;
|
||||
closeAllOpenTradesAt = NULL;
|
||||
restrictionsPeriod = XTRADE_RESTRICATION_NONE;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user