This commit is contained in:
2025-09-17 23:40:07 +03:30
parent 177d115de6
commit 4c9fe89fad
8 changed files with 208 additions and 70 deletions
+2
View File
@@ -605,6 +605,7 @@ class XCBaseExpert : public XCBase
* @return ( bool )
*/
bool HandleCanAnalyseEventTriggered(
string name,
string symbol,
ENUM_TIMEFRAMES period,
datetime time //
@@ -612,6 +613,7 @@ class XCBaseExpert : public XCBase
{
//
return eaTradeManager.CanAnalyse(
name,
symbol,
period,
time //
+5
View File
@@ -442,6 +442,11 @@ class XCBaseSignaller : public XCBase
signal.period = period;
signal.volume = volume;
signal.time = TimeCurrent();
signal.type =
isBullish
? POSITION_TYPE_BUY
: POSITION_TYPE_SELL;
signal.mode = X_ORDER_MODE_MARKET;
//
// Validate Signal ...
+95 -30
View File
@@ -239,59 +239,79 @@ class XCTradeManager : public XCBase
{
//
// Determines Required Parts ...
bool hasSymbol = iPartsCount >= 1;
bool hasPeriod = iPartsCount >= 2;
bool hasSessionsDescriptor = iPartsCount >= 3;
bool hasMaxAllowedSpred = iPartsCount >= 4;
bool hasMaxAllowedPositios = iPartsCount >= 5;
bool hasRestrictionDescriptor = iPartsCount >= 6;
bool hasName = iPartsCount >= 1;
bool hasSymbol = iPartsCount >= 2;
bool hasPeriod = iPartsCount >= 3;
bool hasSessionsDescriptor = iPartsCount >= 4;
bool hasMaxAllowedSpred = iPartsCount >= 5;
bool hasMaxAllowedPositios = iPartsCount >= 6;
bool hasRestrictionDescriptor = iPartsCount >= 7;
//
// Parts IDX ...
int partsIDX = 0;
//
// Extract Name ...
string iName =
hasName
? iParts[partsIDX]
: "";
iName = EscapeString(iName);
partsIDX++;
//
// Extract Symbol ...
string iSymbol =
hasSymbol
? iParts[0]
? iParts[partsIDX]
: _Symbol;
iSymbol = EscapeString(iSymbol);
iSymbol = NormalizeSymbol(iSymbol);
partsIDX++;
//
// Extract Period ...
ENUM_TIMEFRAMES iPeriod =
hasPeriod
? ToPeriod(EscapeString(iParts[1]))
? ToPeriod(EscapeString(iParts[partsIDX]))
: _Period;
iPeriod = NormalizePeriod(iPeriod);
//
// Extract Max Allowed Sspread ...
double iMaxAllowedSpread =
hasMaxAllowedSpred
? (double)(EscapeString(iParts[3]))
: 25;
//
// Extract Max Allowedd Positions ...
int iMaxAllowedPositions =
hasMaxAllowedPositios
? (int)(EscapeString(iParts[4]))
: 5;
partsIDX++;
//
// Extract Sessions Descriptor ...
string iSessionsDescriptor =
hasSessionsDescriptor
? iParts[2]
? iParts[partsIDX]
: "";
iSessionsDescriptor = EscapeString(iSessionsDescriptor);
partsIDX++;
//
// Extract Max Allowed Sspread ...
double iMaxAllowedSpread =
hasMaxAllowedSpred
? (double)(EscapeString(iParts[partsIDX]))
: 25;
partsIDX++;
//
// Extract Max Allowedd Positions ...
int iMaxAllowedPositions =
hasMaxAllowedPositios
? (int)(EscapeString(iParts[partsIDX]))
: 5;
partsIDX++;
//
// Extract Restrictions Descriptor ...
string iRestrictionsDescriptor =
hasRestrictionDescriptor
? iParts[5]
? iParts[partsIDX]
: "";
iRestrictionsDescriptor = EscapeString(iRestrictionsDescriptor);
partsIDX++;
//
XSymbolTradeConfig iConfig;
@@ -299,6 +319,7 @@ class XCTradeManager : public XCBase
//
// Initialize Config ...
has = iConfig.Init(
iName,
iSymbol,
iPeriod,
iSessionsDescriptor,
@@ -731,6 +752,7 @@ class XCTradeManager : public XCBase
* @return ( bool )
*/
bool CanAnalyse(
string name,
string symbol,
ENUM_TIMEFRAMES period,
datetime time //
@@ -743,7 +765,8 @@ class XCTradeManager : public XCBase
// Finding Symbol Configuration Index ...
int idx = FindSymbolConfigurationIndex(
symbol,
period //
period,
name //
);
//
@@ -834,6 +857,7 @@ class XCTradeManager : public XCBase
//
// Check Sessions and Restrictions ...
result = CanAnalyse(
signal.provider,
signal.symbol,
signal.period,
signal.time //
@@ -847,6 +871,47 @@ class XCTradeManager : public XCBase
return result;
}
//
// Check Signal Spread ...
int idx = FindSymbolConfigurationIndex(
signal.symbol,
signal.period,
signal.provider //
);
if (IsValidIndex(idx))
{
//
double spread = GetSpread(signal.symbol);
result =
symbolTradeConfigs[idx].maxAllowedSpread > 0
? spread <= symbolTradeConfigs[idx].maxAllowedSpread
: true;
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_SPREAD;
//
return result;
}
//
// Checking Max Allowed Positions ...
XPosition positions[];
ENUM_X_POSITION_TYPES mType = IsLong(signal.type)
? X_POSITION_TYPE_LONG
: X_POSITION_TYPE_SHORT;
int positionsCount = trader.GetPositions(
positions,
symbolTradeConfigs[idx].symbol,
signal.provider,
symbolTradeConfigs[idx].period,
mType,
true, // Filter By Magic ...
true // Force Clean ...
);
}
//
return result;
}
@@ -954,9 +1019,6 @@ class XCTradeManager : public XCBase
//
if (result)
{
//
// TODO: Complete this ...
//
// Create Trade Struct ...
XTradeInfo iTrade;
@@ -2202,7 +2264,8 @@ class XCTradeManager : public XCBase
//
int FindSymbolConfigurationIndex(
string symbol,
ENUM_TIMEFRAMES period //
ENUM_TIMEFRAMES period,
string name //
)
{
//
@@ -2211,6 +2274,7 @@ class XCTradeManager : public XCBase
//
// Validate Args ...
if (
!IsSpecifiedValid(name) ||
!IsSpecifiedValid(symbol) ||
!IsSpecifiedValid(period) ||
!HasChild(symbolTradeConfigs))
@@ -2223,7 +2287,8 @@ class XCTradeManager : public XCBase
for (int i = 0; i < count; i++)
{
//
if (symbolTradeConfigs[i].symbol == symbol &&
if (symbolTradeConfigs[i].name == name &&
symbolTradeConfigs[i].symbol == symbol &&
symbolTradeConfigs[i].period == period)
{
//