diff --git a/Classes/x-saherelm.x-expert.class.mq5 b/Classes/x-saherelm.x-expert.class.mq5 index ab3942bb..1bc5d5d0 100644 --- a/Classes/x-saherelm.x-expert.class.mq5 +++ b/Classes/x-saherelm.x-expert.class.mq5 @@ -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 // diff --git a/Classes/x-saherelm.x-signaller.class.mq5 b/Classes/x-saherelm.x-signaller.class.mq5 index 13ca2611..c84594bc 100644 --- a/Classes/x-saherelm.x-signaller.class.mq5 +++ b/Classes/x-saherelm.x-signaller.class.mq5 @@ -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 ... diff --git a/Classes/x-saherelm.x-trade-manager.class.mq5 b/Classes/x-saherelm.x-trade-manager.class.mq5 index b1b3d3bd..8bacb715 100644 --- a/Classes/x-saherelm.x-trade-manager.class.mq5 +++ b/Classes/x-saherelm.x-trade-manager.class.mq5 @@ -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) { // diff --git a/Experts/x-saherelm.x-expert.ea.mq5 b/Experts/x-saherelm.x-expert.ea.mq5 index 363634e9..09b90543 100644 --- a/Experts/x-saherelm.x-expert.ea.mq5 +++ b/Experts/x-saherelm.x-expert.ea.mq5 @@ -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 ... diff --git a/Experts/x-saherelm.xfima.ea.mq5 b/Experts/x-saherelm.xfima.ea.mq5 index 0a43a8f2..0e980bff 100644 --- a/Experts/x-saherelm.xfima.ea.mq5 +++ b/Experts/x-saherelm.xfima.ea.mq5 @@ -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 ... diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index fe622816..09db4419 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -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 // diff --git a/XFIMA/Classes/x-saherelm.xfima.expert.class.mq5 b/XFIMA/Classes/x-saherelm.xfima.expert.class.mq5 index c23be68d..8d3729be 100644 --- a/XFIMA/Classes/x-saherelm.xfima.expert.class.mq5 +++ b/XFIMA/Classes/x-saherelm.xfima.expert.class.mq5 @@ -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); } /** diff --git a/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 index a1ea45b9..892a5e48 100644 --- a/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -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);