diff --git a/.vscode/vscode-kanban.json b/.vscode/vscode-kanban.json index 5fba3284..91d427be 100644 --- a/.vscode/vscode-kanban.json +++ b/.vscode/vscode-kanban.json @@ -1,5 +1,58 @@ { - "todo": [ + "todo": [], + "in-progress": [ + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-17T00:01:04.987Z", + "description": { + "content": "- Max Number;\n- Voluem Multiplier;\n- Max Volume;\n- Support on Distance;", + "mime": "text/markdown" + }, + "id": "81", + "references": [], + "title": "Fix Allow Supports ..." + }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-16T23:58:59.163Z", + "description": { + "content": "Fix Open Signals When Support Signals only Open\nMax Allowed Trades Handler ...", + "mime": "text/markdown" + }, + "id": "79", + "references": [], + "title": "Fix Max Allowed Trade on Only SUpport Signals" + } + ], + "testing": [ + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-16T23:57:54.021Z", + "id": "78", + "references": [], + "title": "add Max Allowe Signals per Symbol" + }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "creation_time": "2024-06-16T23:59:52.125Z", + "description": { + "content": "- Start Time;\n- End Time;\n- Close On Specific;\n- Close On Opposite;", + "mime": "text/markdown" + }, + "id": "80", + "references": [], + "title": "Complete Signalling COntrols ..." + } + ], + "done": [ { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -14,38 +67,6 @@ "references": [], "title": "Add all Trail and Position State Managements inside Guards" }, - { - "assignedTo": { - "name": "Hadi Khazaee Asl" - }, - "category": "X121 EA", - "creation_time": "2024-05-30T21:47:35.252Z", - "details": { - "content": "Senario 1:\n- when a new Position Recieved and Executed;\n- detect all Same Symbol/Period Provider Positions;\n- if All exists open positions running in profit;\n- detect nearest entry and put all SLs in it;", - "mime": "text/markdown" - }, - "id": "66", - "references": [], - "title": "Position Management Senarios" - }, - { - "assignedTo": { - "name": "Hadi Khazaee Asl" - }, - "category": "XTrade", - "creation_time": "2024-05-30T21:33:31.361Z", - "description": { - "content": "implement a mechanism to waits for breakout signals entry then Execute Signals;", - "mime": "text/markdown" - }, - "id": "61", - "references": [], - "title": "Signal Executing On Breakouts" - } - ], - "in-progress": [], - "testing": [], - "done": [ { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -749,6 +770,20 @@ "references": [], "title": "Move Support and Resistance Pivots Finders inside X121Market Class" }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "category": "X121 EA", + "creation_time": "2024-05-30T21:47:35.252Z", + "details": { + "content": "Senario 1:\n- when a new Position Recieved and Executed;\n- detect all Same Symbol/Period Provider Positions;\n- if All exists open positions running in profit;\n- detect nearest entry and put all SLs in it;", + "mime": "text/markdown" + }, + "id": "66", + "references": [], + "title": "Position Management Senarios" + }, { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -786,6 +821,20 @@ "mime": "text/markdown" } }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "category": "XMQL", + "creation_time": "2024-06-01T00:57:10.458Z", + "description": { + "content": "do r&d about Volume Profiling and Implement it inside X121 Market Cycle;", + "mime": "text/markdown" + }, + "id": "72", + "references": [], + "title": "R&D about Volume Profiling" + }, { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -900,6 +949,20 @@ "references": [], "title": "resolve InvalidStop on Partial Closing" }, + { + "assignedTo": { + "name": "Hadi Khazaee Asl" + }, + "category": "XTrade", + "creation_time": "2024-05-30T21:33:31.361Z", + "description": { + "content": "implement a mechanism to waits for breakout signals entry then Execute Signals;", + "mime": "text/markdown" + }, + "id": "61", + "references": [], + "title": "Signal Executing On Breakouts" + }, { "assignedTo": { "name": "Hadi Khazaee Asl" @@ -944,20 +1007,6 @@ "content": "do a refactor on all brokers, higgh priority criterias ...", "mime": "text/markdown" } - }, - { - "assignedTo": { - "name": "Hadi Khazaee Asl" - }, - "category": "XMQL", - "creation_time": "2024-06-01T00:57:10.458Z", - "description": { - "content": "do r&d about Volume Profiling and Implement it inside X121 Market Cycle;", - "mime": "text/markdown" - }, - "id": "72", - "references": [], - "title": "R&D about Volume Profiling" } ] } \ No newline at end of file diff --git a/Classes/x-saherelm.x121.setup.xea.mq5 b/Classes/x-saherelm.x121.setup.xea.mq5 index d1c93462..add716af 100644 --- a/Classes/x-saherelm.x121.setup.xea.mq5 +++ b/Classes/x-saherelm.x121.setup.xea.mq5 @@ -1045,97 +1045,6 @@ public: mSave = value; } - // - // Supporting ... - - // - bool AllowSupport() - { - return mAllowSupport; - } - - // - void AllowSupport(bool value) - { - mAllowSupport = value; - } - - // - int MaxNumberOfSupports() - { - return mMaxNumberOfSupports; - } - - // - void MaxNumberOfSupports(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxNumberOfSupports = value; - } - - // - double SupportVolumeMultiplier() - { - return mSupportVolumeMultiplier; - } - - // - void SupportVolumeMultiplier(double value) - { - // - if (value < 1) - { - value = 1; - } - - // - mSupportVolumeMultiplier = value; - } - - // - double MaxAllowedSupportVolume() - { - return mMaxAllowedSupportVolume(); - } - - // - void MaxAllowedSupportVolume(double value) - { - // - if (value < 0.01) - { - value = 0.01; - } - - // - mMaxAllowedSupportVolume = value; - } - - // - bool EnableSupport() - { - // - bool result = false; - - // - result = - // - AllowSupport() && - MaxNumberOfSupports() > 0 && - SupportVolumeMultiplier() > 0 - // - ; - - // - return result; - } - // // Trailling Stop ... @@ -1249,7 +1158,116 @@ public: } // - // Grid System ... + // Supporting ... + + // + bool AllowSupport() + { + return mAllowSupport; + } + + // + void AllowSupport(bool value) + { + mAllowSupport = value; + } + + // + double SupportDistance() + { + return mSupportDistance; + } + + // + void SupportDistance(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSupportDistance = value; + } + + // + int MaxNumberOfSupports() + { + return mMaxNumberOfSupports; + } + + // + void MaxNumberOfSupports(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxNumberOfSupports = value; + } + + // + double SupportVolumeMultiplier() + { + return mSupportVolumeMultiplier; + } + + // + void SupportVolumeMultiplier(double value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSupportVolumeMultiplier = value; + } + + // + double MaxAllowedSupportVolume() + { + return mMaxAllowedSupportVolume; + } + + // + void MaxAllowedSupportVolume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mMaxAllowedSupportVolume = value; + } + + // + bool EnableSupport() + { + // + bool result = false; + + // + result = + // + AllowSupport() && + SupportVolumeMultiplier() > 0 + // + ; + + // + return result; + } + + // + // Grid ... // bool AllowGrid() @@ -1263,6 +1281,25 @@ public: mAllowGrid = value; } + // + int MaxNumberOfGrids() + { + return mMaxNumberOfGrids; + } + + // + void MaxNumberOfGrids(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxNumberOfGrids = value; + } + // double GridDistance() { @@ -1292,15 +1329,34 @@ public: void GridVolumeMultiplier(double value) { // - if (value <= 1) + if (value < 1) { - value = 0; + value = 1; } // mGridVolumeMultiplier = value; } + // + double MaxAllowedGridVolume() + { + return mMaxAllowedGridVolume; + } + + // + void MaxAllowedGridVolume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mMaxAllowedGridVolume = value; + } + // // Check Grid Properties to Validate it's Enable or not ... bool EnableGrid() @@ -1336,6 +1392,25 @@ public: mAllowRecovery = value; } + // + int MaxNumberOfRecoveries() + { + return mMaxNumberOfRecoveries; + } + + // + void MaxNumberOfRecoveries(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxNumberOfRecoveries = value; + } + // double RecoveryDistance() { @@ -1365,15 +1440,34 @@ public: void RecoveryVolumeMultiplier(double value) { // - if (value <= 1) + if (value < 1) { - value = 0; + value = 1; } // mRecoveryVolumeMultiplier = value; } + // + double MaxAllowedRecoveryVolume() + { + return mMaxAllowedRecoveryVolume; + } + + // + void MaxAllowedRecoveryVolume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mMaxAllowedRecoveryVolume = value; + } + // // Check Recovery Properties to Validate it's Enable or not ... bool EnableRecovery() @@ -1675,9 +1769,150 @@ public: Finish(infoIDX); } + // + // Sync ... + void Sync() + { + // + int count = Count(); + if (!IsValidSize(count)) + { + return; + } + + // + int mustRemoved[]; + for (int i = 0; i < count; i++) + { + // + XTradeInfo iInfo = data[i]; + + // + if (iInfo.ticket > 0 && !mTrader.IsOpen(iInfo.ticket)) + { + // + AddSpecific( + i, + mustRemoved // + ); + } + } + + // + int mustRemovedCount = ArraySize(mustRemoved); + if (!IsValidSize(mustRemovedCount)) + { + return; + } + + // + for (int i = 0; i < mustRemovedCount; i++) + { + // + ArrayRemove( + data, + i, + 1 // + ); + } + } + // // Protection Handlers ... + // + // Handle Do All Protecting ... + int DoProtect( + XSignal &signals[] // if PRotecting Generate Some Support Signals, Holds them here + ) + { + // + int result = 0; + + // + // Calling Protection Algorithms ... + + // + result = ArraySize(signals); + + // + return result; + } + + // + // Protected ... +protected: + // + // Props ... + XSCTrade *mTrader; + XTradeInfo data[]; + XTradeInfoCollector *collector; + + // + bool mSave; // Save Results ... + + // + // Trailling ... + bool mAllowTrailStop; // Enable Trailling Stop Losses + double mNextTrailPoint; // Next Trailling Step + double mFirstTrailPoint; // First Stop Trail + double mFirstTrailDistance; // Start Trailling Distance + double mNextTrailDistance; // Next Trailling Distance + + // + // Supporting ... + bool mAllowSupport; // Allow Support Signals + double mSupportDistance; // Supporting Distance + int mMaxNumberOfSupports; // Max Number of Support Signals + double mSupportVolumeMultiplier; // Support Signals Volume Multiplier + double mMaxAllowedSupportVolume; // Max Allowed Support Signals Volume + + // + // Grid ... + bool mAllowGrid; // Allow Grid Signals + int mMaxNumberOfGrids; // Max Number of Grid Signals + double mGridDistance; // Grid Distance + double mGridVolumeMultiplier; // Grid Volume Multiplier + double mMaxAllowedGridVolume; // Max Allowed Grid Signals Volume + + // + // Recovery ... + bool mAllowRecovery; // Allow Recovery Signals + int mMaxNumberOfRecoveries; // Max Number of Recovery Signals + double mRecoveryDistance; // Recovery Distance + double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier + double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Signals Volume + + // + // Tools ... + + // + void Finish(int index) + { + // + XTradeInfo info = data[index]; + if (!info.IsValid()) + { + return; + } + + // + ArrayRemove( + data, + index, + 1 // + ); + + // + if (GetSave()) + { + collector.Save(info); + } + } + + // + // Protection Methods ... + // int HandleTrailling() { @@ -2113,117 +2348,6 @@ public: return result; } - // - // Sync ... - void Sync() - { - // - int count = Count(); - if (!IsValidSize(count)) - { - return; - } - - // - int mustRemoved[]; - for (int i = 0; i < count; i++) - { - // - XTradeInfo iInfo = data[i]; - - // - if (iInfo.ticket > 0 && !mTrader.IsOpen(iInfo.ticket)) - { - // - AddSpecific( - i, - mustRemoved // - ); - } - } - - // - int mustRemovedCount = ArraySize(mustRemoved); - if (!IsValidSize(mustRemovedCount)) - { - return; - } - - // - for (int i = 0; i < mustRemovedCount; i++) - { - // - ArrayRemove( - data, - i, - 1 // - ); - } - } - - // - // Protected ... -protected: - // - // Props ... - XSCTrade *mTrader; - XTradeInfo data[]; - XTradeInfoCollector *collector; - - // - bool mSave; // Save Results ... - - // - // Tools ... - - // - void Finish(int index) - { - // - XTradeInfo info = data[index]; - if (!info.IsValid()) - { - return; - } - - // - ArrayRemove( - data, - index, - 1 // - ); - - // - if (GetSave()) - { - collector.Save(info); - } - } - - // - // Supports ... - bool mAllowSupport; // Allow Support Signals - - // - // Stop Trailling ... - bool mAllowTrailStop; // Enable Trailling Stop Losses - double mFirstTrailDistance; // Start Trailling Distance - double mFirstTrailPoint; // First Stop Trail - double mNextTrailDistance; // Next Trailling Distance - double mNextTrailPoint; // Next Trailling Step - - // - // Grid ... - bool mAllowGrid; // Use Grid System to Recovery Positions - double mGridDistance; // Grid System Distance - double mGridVolumeMultiplier; // Grid System Volume Multiplier - - // - // Recovery ... - bool mAllowRecovery; // Use Recovery System to Recovery Positions - double mRecoveryDistance; // Recovery System Distance - double mRecoveryVolumeMultiplier; // Recovery System Volume Multiplier - // int FindSetupIndex( string symbol, @@ -2499,7 +2623,7 @@ public: // mMaxAllowedTrades = value; - mTrader.SetMaxAllowedPositions(value); + // mTrader.SetMaxAllowedPositions(value); } // @@ -2676,6 +2800,18 @@ public: mTradeHandler.AllowSupport(value); } + // + double SupportDistance() + { + return mTradeHandler.SupportDistance(); + } + + // + void SupportDistance(double value) + { + mTradeHandler.SupportDistance(value); + } + // int MaxNumberOfSupports() { @@ -2889,7 +3025,8 @@ public: // filters theme here and passed them // for Executing ... int RequestForSignal( - XSignal &signals[] // Holds Signals ... + XSignal &signals[], // Holds Signals ... + bool force = false // ) override { // @@ -2899,9 +3036,13 @@ public: Clean(signals); // - if (!IsEnable()) + if (!force) { - return result; + // + if (!IsEnable()) + { + return result; + } } // @@ -2957,6 +3098,7 @@ public: X121SetupConditions hConditions; // + int maxAllowed = MaxAllowedTrades(); X121SignalGenerator signalGenerator; // @@ -3047,7 +3189,7 @@ public: cSignal, cPusher, cProvider, - mUseSupport, + AllowSupport(), mAllowLong, mAllowShort, mVolume, @@ -3110,7 +3252,7 @@ public: sSignal, sPusher, sProvider, - mUseSupport, + AllowSupport(), mAllowLong, mAllowShort, mVolume, @@ -3173,7 +3315,7 @@ public: mSignal, mPusher, mProvider, - mUseSupport, + AllowSupport(), mAllowLong, mAllowShort, mVolume, @@ -3236,7 +3378,7 @@ public: lSignal, lPusher, lProvider, - mUseSupport, + AllowSupport(), mAllowLong, mAllowShort, mVolume, @@ -3299,7 +3441,7 @@ public: hSignal, hPusher, hProvider, - mUseSupport, + AllowSupport(), mAllowLong, mAllowShort, mVolume, @@ -3543,6 +3685,7 @@ public: // XSignal tmpSignals[]; + XSignal eSignals[]; // Must Executed Copy( signals, tmpSignals // @@ -3551,12 +3694,18 @@ public: // Clean(signals); + // + int maxAllowed = MaxAllowedTrades(); + // for (int i = 0; i < signalsCount; i++) { // XSignal iSignal = tmpSignals[i]; + // + bool isSignalValid = false; + // // Handle Close All Positions when Opposit Signal Recieved ... if (mCloseOnOpposit) @@ -3598,12 +3747,44 @@ public: } // - AddRef( - iSignal, - signals // - ); + // Filter Signals Based On Max Allowed ... + if (maxAllowed > 0) + { + XPosition iSymbolsPositions[]; + int iSymbolsPositionsCount = mTrader.GetPositions( + iSymbolsPositions, + iSignal.symbol, + NULL, + NULL, + NULL, + true // + ); + isSignalValid = iSymbolsPositionsCount < maxAllowed; + if (!isSignalValid) + { + continue; + } + } + else + { + isSignalValid = true; + } + + // + if (isSignalValid) + { + // + AddRef( + iSignal, + eSignals // + ); + } } + // + // Cutom Signal Execution ... + HandleSignals(eSignals); + // result = ArraySize(signals); @@ -3629,7 +3810,7 @@ public: // Do all State Management here ... // - DoEQMHedge(); + DoHedge(); // // Handle Close All Positions on Specific Time ... @@ -3728,9 +3909,41 @@ protected: // Tools ... // + // Check Signalling Enable or not ... bool IsEnable() { - return mAllowLong || mAllowShort; + // + bool result = false; + + // + // Check Signal Type is Enabled or not ... + bool isTypePassed = mAllowLong || mAllowShort; + + // + // Check Signalling Time ... + MqlDateTime cTime; + bool isTimeRecieved = TimeCurrent(cTime); + + // + int endHour = EndSignallingHoure(); + int startHour = StartSignallingHoure(); + + // + bool isStartHourPassed = + startHour <= -1 + ? true + : cTime.hour >= startHour; + bool isEndHourPassed = + endHour <= -1 + ? true + : cTime.hour < endHour; + bool isTimePassed = isTimeRecieved && isStartHourPassed && isEndHourPassed; + + // + result = isTypePassed && isTimePassed; + + // + return result; } // @@ -3761,6 +3974,26 @@ protected: return result; } + // + // Custom Signal Execution ... + void HandleSignals(XSignal &signals[]) + { + // + int signalsCount = ArraySize(signals); + if (!IsValidSize(signals)) + { + return; + } + + // + ENUM_X_SIGNAL_EXECUTION_RESULT states[]; + int executedSignalsCount = ExecuteSignals( + signals, + states, + false // + ); + } + // // Private ... private: @@ -3978,303 +4211,18 @@ private: return EnableGrid() || EnableRecovery() || EnableTrailling() || AllowSupport(); } - // - // Remove Untriggered EQM Orders ... - void RemoveEQMOrders() - { - // - RemoveDraws("XTRND"); - - // - XOrder supports[]; - int supportsCount = mTrader.GetOrders( - supports, - NULL, // All Symbols ... - XEQMSupportToken, // Only EQM Supports ... - NULL, // All Periods ... - X_POSITION_TYPE_ALL, // All Order Types ... - ORDER_STATE_PLACED, // Untriggered Orders ... - true // Filter by Magic ... - ); - if (!IsValidSize(supportsCount)) - { - return; - } - - // - int cancelled = mTrader.CancelOrders( - supports // - ); - - // - if (IsValidSize(cancelled)) - { - // - string message = XEQMSupportToken + " Cancel " + ToString(cancelled) + " Supports ..."; - - // - Alert(message); - } - } - - // - // Place EQM Orders ... - void PlaceEQMOrders() - { - // - int count = CountSetups(); - if (!IsValidSize(count)) - { - return; - } - - // - XSignal supports[]; - - // - for (int i = 0; i < count; i++) - { - // - string iSymbol = mSetups[i].GetSymbol(); - ENUM_TIMEFRAMES iPeriod = NULL; // All Periods ... - string iProvider = NULL; // All Providers ... - - // - XPosition iPositions[]; - int iPositionsCount = mTrader.GetPositions( - iPositions, - iSymbol, - iProvider, - iPeriod, - X_POSITION_TYPE_ALL // - ); - if (!IsValidSize(iPositionsCount)) - { - continue; - } - - // - int maxInDIDX = FindMaxDrawdownIndex( - iPositions // - ); - if (!IsValidIndex(maxInDIDX)) - { - continue; - } - - // - XPosition maxInDP = iPositions[maxInDIDX]; - bool isLong = IsLong(maxInDP.type); - - // - XOHCL iZBar; - bool isInited = iZBar.Init( - iSymbol, - iPeriod, - 0 // - ); - if (!isInited) - { - continue; - } - - // - double iSupport = 0; - double iResistance = 0; - bool isDrawn = DrawTrendState( - ChartID(), - "XTRND", - iZBar, - iSupport, - iResistance // - ); - if (isDrawn) - { - // - XSignal iSignal; - - // - double iSL = 0; - double iTP = 0; - double iEntry = 0; - ENUM_POSITION_TYPE iType; - ENUM_X_ORDER_MODES iMode; - double iVolume = maxInDP.volume * 3; - - // - if (iSupport > 0 && isLong && iSupport > maxInDP.sl && maxInDP.sl > 0) - { - // - // Add Short Support for Long ... - iEntry = iSupport; - iSL = maxInDP.tp; - iTP = maxInDP.sl; - iMode = X_ORDER_MODE_STOP; - iType = POSITION_TYPE_SELL; - - // - bool isPrepared = iSignal.Prepare( - iSymbol, - XEQMSupportToken, - iPeriod, - iType, - iMode, - iEntry, - iVolume, - iSL, - iTP // - ); - if (isPrepared) - { - // - iSignal.comment = GenerateSupportTag(maxInDP.ticket); - - // - AddRef( - iSignal, - supports /// - ); - - // - iSignal.Clean(); - } - } - - // - if (iResistance > 0 && !isLong && iResistance < maxInDP.sl && maxInDP.sl > 0) - { - // - // Add Long Support for Short ... - iEntry = iResistance; - iSL = maxInDP.tp; - iTP = maxInDP.sl; - iMode = X_ORDER_MODE_STOP; - iType = POSITION_TYPE_BUY; - - // - bool isPrepared = iSignal.Prepare( - iSymbol, - XEQMSupportToken, - iPeriod, - iType, - iMode, - iEntry, - iVolume, - iSL, - iTP // - ); - if (isPrepared) - { - // - iSignal.comment = GenerateSupportTag(maxInDP.ticket); - - // - AddRef( - iSignal, - supports /// - ); - - // - iSignal.Clean(); - } - } - } - } - - // - int supportsCount = ArraySize(supports); - if (!IsValidSize(supportsCount)) - { - return; - } - - // - ENUM_X_SIGNAL_EXECUTION_RESULT states[]; - int executeds = mTrader.ExecuteSignals( - supports, - states, - ORDER_TIME_GTC, - false, - false // Ignore Policies - ); - if (IsValidSize(executeds)) - { - // - string message = XEQMSupportToken + " Execute " + ToString(executeds) + " Supports ..."; - - // - Alert(message); - } - } - // // Do Gridding Mechanism ... void DoEQMProtect() { // - if (!EnableProtection()) - { - return; - } + XSignal supports[]; + int supportsCount = mTradeHandler.DoProtect(supports); // - // Trailling ... - if (EnableTrailling()) + if (IsValidSize(supportsCount)) { - // - int trailsCount = mTradeHandler.HandleTrailling(); - if (IsValidSize(trailsCount)) - { - // - string message = XEQMSupportToken + " Successfully Trail Stop for: " + ToString(trailsCount) + " Position(s) ..."; - - // - // Alert(message); - } - } - - // - // Support ... - if (AllowSupport()) - { - // - XSignal supports[]; - int supportsCount = mTradeHandler.RequestForSupport( - supports, - mSetups // - ); - if (IsValidSize(supportsCount)) - { - EQMExecuteSignals(supports); - } - } - - // - // Grid ... - if (EnableGrid()) - { - // - XSignal signals[]; - int signalsCount = mTradeHandler - .RequestForGrid(signals); - if (IsValidSize(signalsCount)) - { - EQMExecuteSignals(signals); - } - } - - // - // Recovery ... - if (EnableRecovery()) - { - // - XSignal signals[]; - int signalsCount = mTradeHandler - .RequestForRecovery(signals); - if (IsValidSize(signalsCount)) - { - EQMExecuteSignals(signals); - } + EQMExecuteSignals(supports); } } diff --git a/Classes/x-saherelm.xea.class.mq5 b/Classes/x-saherelm.xea.class.mq5 index 844f84f6..a2132505 100644 --- a/Classes/x-saherelm.xea.class.mq5 +++ b/Classes/x-saherelm.xea.class.mq5 @@ -945,27 +945,34 @@ protected: } // - // Signal Event Listeners ... - - // - void NotifyOnSignalEventHandlers(XSignal &signal) + int CancelOrders() { // - int listenersCount = ArraySize(mOnSignalEventHandlers); - if (listenersCount <= 0) + int result = 0; + + // + XOrder supports[]; + int supportsCount = mTrader.GetOrders( + supports, + NULL, // All Symbols ... + XEQMSupportToken, // Only EQM Supports ... + NULL, // All Periods ... + X_POSITION_TYPE_ALL, // All Order Types ... + ORDER_STATE_PLACED, // Untriggered Orders ... + true // Filter by Magic ... + ); + if (!IsValidSize(supportsCount)) { - return; + return result; } // - for (int i = 0; i < listenersCount; i++) - { - // - TOnSignal iListener = mOnSignalEventHandlers[i]; + result = mTrader.CancelOrders( + supports // + ); - // - iListener(signal); - } + // + return result; } // @@ -1069,7 +1076,7 @@ protected: // // Check Hedge Conditions is Happens or not ... // if true doing Hedge ... - bool DoEQMHedge() + bool DoHedge() { // bool result = false; @@ -1148,6 +1155,30 @@ protected: return result; } + // + // Signal Event Listeners ... + + // + void NotifyOnSignalEventHandlers(XSignal &signal) + { + // + int listenersCount = ArraySize(mOnSignalEventHandlers); + if (listenersCount <= 0) + { + return; + } + + // + for (int i = 0; i < listenersCount; i++) + { + // + TOnSignal iListener = mOnSignalEventHandlers[i]; + + // + iListener(signal); + } + } + // // Guards ... diff --git a/Documents/BKP/usefull.mq5 b/Documents/BKP/usefull.mq5 index 1341cc4c..22dda354 100644 --- a/Documents/BKP/usefull.mq5 +++ b/Documents/BKP/usefull.mq5 @@ -1142,3 +1142,198 @@ ); bullishScore += tmpBullishScore; bearishScore += tmpBearishScore; + + + +//////////////////////////////////////////////////////// + + + // + // Place EQM Orders ... + void PlaceEQMOrders() + { + // + int count = CountSetups(); + if (!IsValidSize(count)) + { + return; + } + + // + XSignal supports[]; + + // + for (int i = 0; i < count; i++) + { + // + string iSymbol = mSetups[i].GetSymbol(); + ENUM_TIMEFRAMES iPeriod = NULL; // All Periods ... + string iProvider = NULL; // All Providers ... + + // + XPosition iPositions[]; + int iPositionsCount = mTrader.GetPositions( + iPositions, + iSymbol, + iProvider, + iPeriod, + X_POSITION_TYPE_ALL // + ); + if (!IsValidSize(iPositionsCount)) + { + continue; + } + + // + int maxInDIDX = FindMaxDrawdownIndex( + iPositions // + ); + if (!IsValidIndex(maxInDIDX)) + { + continue; + } + + // + XPosition maxInDP = iPositions[maxInDIDX]; + bool isLong = IsLong(maxInDP.type); + + // + XOHCL iZBar; + bool isInited = iZBar.Init( + iSymbol, + iPeriod, + 0 // + ); + if (!isInited) + { + continue; + } + + // + double iSupport = 0; + double iResistance = 0; + bool isDrawn = DrawTrendState( + ChartID(), + "XTRND", + iZBar, + iSupport, + iResistance // + ); + if (isDrawn) + { + // + XSignal iSignal; + + // + double iSL = 0; + double iTP = 0; + double iEntry = 0; + ENUM_POSITION_TYPE iType; + ENUM_X_ORDER_MODES iMode; + double iVolume = maxInDP.volume * 3; + + // + if (iSupport > 0 && isLong && iSupport > maxInDP.sl && maxInDP.sl > 0) + { + // + // Add Short Support for Long ... + iEntry = iSupport; + iSL = maxInDP.tp; + iTP = maxInDP.sl; + iMode = X_ORDER_MODE_STOP; + iType = POSITION_TYPE_SELL; + + // + bool isPrepared = iSignal.Prepare( + iSymbol, + XEQMSupportToken, + iPeriod, + iType, + iMode, + iEntry, + iVolume, + iSL, + iTP // + ); + if (isPrepared) + { + // + iSignal.comment = GenerateSupportTag(maxInDP.ticket); + + // + AddRef( + iSignal, + supports /// + ); + + // + iSignal.Clean(); + } + } + + // + if (iResistance > 0 && !isLong && iResistance < maxInDP.sl && maxInDP.sl > 0) + { + // + // Add Long Support for Short ... + iEntry = iResistance; + iSL = maxInDP.tp; + iTP = maxInDP.sl; + iMode = X_ORDER_MODE_STOP; + iType = POSITION_TYPE_BUY; + + // + bool isPrepared = iSignal.Prepare( + iSymbol, + XEQMSupportToken, + iPeriod, + iType, + iMode, + iEntry, + iVolume, + iSL, + iTP // + ); + if (isPrepared) + { + // + iSignal.comment = GenerateSupportTag(maxInDP.ticket); + + // + AddRef( + iSignal, + supports /// + ); + + // + iSignal.Clean(); + } + } + } + } + + // + int supportsCount = ArraySize(supports); + if (!IsValidSize(supportsCount)) + { + return; + } + + // + ENUM_X_SIGNAL_EXECUTION_RESULT states[]; + int executeds = mTrader.ExecuteSignals( + supports, + states, + ORDER_TIME_GTC, + false, + false // Ignore Policies + ); + if (IsValidSize(executeds)) + { + // + string message = XEQMSupportToken + " Execute " + ToString(executeds) + " Supports ..."; + + // + Alert(message); + } + } diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index b87abff9..271a82fe 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -74,6 +74,7 @@ input double x121EANextTrailPoint = 10; // Next Trailling Step // input group "Supporting"; input bool x121EAAllowSupport = false; // Allow Support Signals +double x121EASupportDistance = 50; // Supporting Distance input int x121EAMaxNumberOfSupports = 1; // Max Number of Support Signals input double x121EASupportVolumeMultiplier = 2.0; // Support Signals Volume Multiplier input double x121EAMaxAllowedSupportVolume = 0.8; // Max Allowed Support Signals Volume @@ -244,6 +245,7 @@ bool InitialEA() // // Supporting ... x121EA.AllowSupport(x121EAAllowSupport); + x121EA.SupportDistance(x121EASupportDistance); x121EA.MaxNumberOfSupports(x121EAMaxNumberOfSupports); x121EA.SupportVolumeMultiplier(x121EASupportVolumeMultiplier); x121EA.MaxAllowedSupportVolume(x121EAMaxAllowedSupportVolume);