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)
{
//
+3 -2
View File
@@ -39,6 +39,7 @@ input string eaLogSuffix = ""; // Log Suffix
//
// Symbols
// [
// Name|
// Symbol|
// period|
// (ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|
@@ -55,8 +56,8 @@ input string eaLogSuffix = ""; // Log Suffix
// ]
//
//
// [XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,1,0,2,0)]
input string eaSymbolConfiguration = "[XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,3,0,2,0)]"; // Symbol Configurations
// [XNAME|XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,1,0,2,0)]
input string eaSymbolConfiguration = "[XNAME|XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,3,0,2,0)]"; // Symbol Configurations
//
// Management ...
+5 -4
View File
@@ -39,6 +39,7 @@ input string eaLogSuffix = ""; // Log Suffix
//
// Symbols
// [
// Name|
// Symbol|
// period|
// (ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|
@@ -55,10 +56,10 @@ input string eaLogSuffix = ""; // Log Suffix
// ]
//
//
// [EURUSDb|M5||25.0|5|]
// [XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,1,0,2,0)]
// [XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,3,0,2,0)]
input string eaSymbolConfiguration = "[EURUSDb|M5||25.0|5|]"; // Symbol Configurations
// [XFIMA1|EURUSDb|M5||25.0|5|]
// [XFIMA1|XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,1,0,2,0)]
// [XFIMA1|XAUUSDb|M5|(ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_20:00)|25.0|5|(XTRADE_RESTRICATION_DAILY,3,0,2,0)]
input string eaSymbolConfiguration = "[XFIMA1|EURUSDb|M5||25.0|5|]"; // Symbol Configurations
//
// Management ...
+10 -2
View File
@@ -2919,6 +2919,7 @@ struct XSymbolTradeConfig
int trades; // All Trades
int losses; // All Loosing Trades
int profits; // All Winning Trades
string name; // Provider Name
string symbol; // Trading Symbol
int managedSLs; // Managed SL(s)
int managedTPs; // Managed TP(s)
@@ -2953,6 +2954,7 @@ struct XSymbolTradeConfig
void Clean()
{
//
name = NULL;
symbol = NULL;
period = NULL;
SpecifiedClean(sessions);
@@ -3003,6 +3005,7 @@ struct XSymbolTradeConfig
* @return ( bool )
*/
bool Init(
string _name,
string _symbol = NULL,
ENUM_TIMEFRAMES _period = NULL,
string _sessionsDescriptor = NULL,
@@ -3020,6 +3023,7 @@ struct XSymbolTradeConfig
_period = NormalizePeriod(_period);
//
name = name;
symbol = _symbol;
period = _period;
maxAllowedSpread = _maxAllowedSpread;
@@ -3052,6 +3056,7 @@ struct XSymbolTradeConfig
// Validate ...
result = IsValid() &&
dest.IsValid() &&
name == dest.name &&
symbol == dest.symbol &&
period == dest.period;
@@ -3067,8 +3072,10 @@ struct XSymbolTradeConfig
bool result = false;
//
result = IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period);
result =
IsSpecifiedValid(name) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period);
//
return result;
@@ -3765,6 +3772,7 @@ typedef void (*TOnSignal)(XSignal &signal);
//
typedef bool (*TCanAnalyse)(
string name,
string _symbol,
ENUM_TIMEFRAMES _period,
datetime _time //
+32 -30
View File
@@ -56,40 +56,42 @@ class XCXFIMAExpret : public XCBaseExpert
//
// Instantiate Signaller ...
//
// XFIMA Inputs ...
//
XFIMAInputs fimaInputs;
fimaInputs.Default();
fimaInputs.Hide();
//
// Instantiate Signaller Class ...
XCXFIMAStrategy1Signaller *fima1Signaller = new XCXFIMAStrategy1Signaller(
symbolConfig.symbol,
symbolConfig.period,
fimaInputs,
false // Process All Ticks ...
);
if (!fima1Signaller.IsValid())
if (symbolConfig.name == "XFIMA1")
{
//
fima1Signaller.Destroy();
delete fima1Signaller;
// XFIMA Inputs ...
//
XFIMAInputs fimaInputs;
fimaInputs.Default();
fimaInputs.Hide();
//
// Instantiate Signaller Class ...
XCXFIMAStrategy1Signaller *fima1Signaller = new XCXFIMAStrategy1Signaller(
symbolConfig.symbol,
symbolConfig.period,
fimaInputs,
false // Process All Ticks ...
);
if (!fima1Signaller.IsValid())
{
//
fima1Signaller.Destroy();
delete fima1Signaller;
ZeroMemory(fima1Signaller);
return;
}
//
// Register Signaller ...
RegisterSignaller((XCBaseSignaller *)fima1Signaller);
//
// Cleanup Resources ...
fimaInputs.Clean();
ZeroMemory(fima1Signaller);
return;
}
//
// Register Signaller ...
RegisterSignaller((XCBaseSignaller *)fima1Signaller);
//
// Cleanup Resources ...
fimaInputs.Clean();
ZeroMemory(fima1Signaller);
}
/**
@@ -262,14 +262,16 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
XOHCL bar;
XSignal signal;
bool has = false;
int cIdx = barIndex + 1;
int pIdx = cIdx + 1;
ENUM_X_DIRECTION signalDir = X_DIRECTION_NONE;
//
// Initialize Bar ...
// Initialize Bar as CBar ...
has = bar.Init(
symbol,
period,
barIndex //
cIdx //
);
if (!has)
{
@@ -299,6 +301,58 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller
//
// Analyse Conditions for Finding Signal ...
//
// TODO: Remove this ...
//
bool isFastCrossedOverSlow =
fimaConditions.maFastBuffer[cIdx] > fimaConditions.maSlowBuffer[cIdx] &&
fimaConditions.maFastBuffer[pIdx] < fimaConditions.maSlowBuffer[pIdx];
//
bool isFastCrossedUnderSlow =
fimaConditions.maFastBuffer[cIdx] < fimaConditions.maSlowBuffer[cIdx] &&
fimaConditions.maFastBuffer[pIdx] > fimaConditions.maSlowBuffer[pIdx];
//
has =
isFastCrossedOverSlow ||
isFastCrossedUnderSlow;
if (has)
{
//
// Do Conditions Validating ...
//
// Bullish Validation ...
bool isBullish =
//
isFastCrossedOverSlow
//
;
//
// Bearish Validation ...
bool isBearish =
//
isFastCrossedUnderSlow
//
;
//
has =
(isBullish && !isBearish) ||
(isBearish && !isBullish);
if (has)
{
//
signalDir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
}
}
//
// Check Signal Founded ...
has = HasDirection(signalDir);