Quick summary
- Places two initial pending stops (BuyStop & SellStop)
- After a stop fill, restructures into stop + limit in the filled direction
- Detects limit fills via limit-count monitoring and resets to the initial dual-stop state
- 5-second watchdog ensures both stop types always exist; if not → reset
- Uses strict magic number & symbol filtering
Important note (profit & exit)
By its market structure, the system is naturally biased toward generating profit over time. However, the EXIT STRATEGY IS NOT IMPLEMENTED yet.
The entry logic is complete — the open task is to find the most efficient way to take profits, preferably without indicators (pure price, time, or volatility based).
Constructive suggestions and testing results are very welcome.
QuoteDislikedThis Expert Advisor (EA) for MetaTrader 5 implements a dynamic cluster-based strategy using alternating Buy/Sell Stop and Buy/Sell Limit pending orders.
The system:
- Automatically switches between Stop and Limit clusters based on order distribution.
- Deletes conflicting or outdated pending orders before placing new clusters.
- Tracks the minimum number of open pending orders, ensuring consistent market presence.
- Closes profitable positions that exceed a customizable threshold in points.
- Reacts to spread conditions dynamically and avoids execution in illiquid moments.
Key parameters such as StopLoss, TakeProfit, cluster size, and spacing can be fine-tuned. The system aims to adapt to market volatility, paving the way for a more responsive, semi-HFT-like behavior.
While this EA doesn't implement true high-frequency trading (HFT), it draws inspiration from HFT principles such as:
- fast cluster-based order placement
- volatility-aware parameters
- conditional execution logic
The long-term goal is to evolve this logic into a scalable micro-scalping framework with real-time market reaction.
Feel free to test, improve, and share feedback. The code is modular and open to enhancements such as:
- Tick volume filtering
- Time-in-force pending order expiration
- Dynamic SL/TP scaling
Let me know if you'd like a cleaner or more technical version (e.g., for GitHub, MQL5.com, or StackOverflow).
Attached File(s)
QuoteDislikedRelease:
After reaching out for feedback on an earlier request regarding my MT4 EA project unnoticed by the eyes of this community, or perhaps it was just not the right time for such an exchange. No worries, though, as I believe in persistence and the power of sharing.
I've decided to take a different approach. Today, I'm presenting a Lite Version of my EA project. My hope is that this simplified version will not only be easier for ChatGPT to process in assisting me but also more accessible for everyone in this community to review, understand, and provide valuable feedback on.
Features :
- Profit and Loss Thresholds: Trades are managed based on specified profit and loss thresholds. The script checks each trade to see if it has exceeded either threshold.
- Closing Trades in Profit: If a trade's profit exceeds the ProfitThreshold and certain conditions regarding the trade's take profit (TP) level are met, the trade is closed. Then, a hedge order with half the lot size of the closed trade is opened to protect against potential losses.
- Managing Losing Trades: For trades falling below the LossThreshold, the script checks if the spread is within an acceptable range and if the trade doesn't have a set TP. If conditions are favorable, it attempts to adjust the trade to break even and opens a hedge order with increased lot size (+0.01 Lot).
- Utility Functions:
- SpreadCheck: Checks if the current spread for the symbol is within an acceptable limit.
- CloseOrder: Closes an order given its ticket and lot size.
- SetTP: Sets the TP for an order, and pervent a trade to be hedged more than once
- OpenHedgeOrder: Opens a hedge order of the opposite type to the original order, with a specified lot size.
I've designed it with the intent to spark a conversation around trading strategies, risk management, and the efficient use of MQL4 to automate these processes. Your insights, critiques, and suggestions are not only welcomed but deeply encouraged. Whether it's a code optimization, strategy refinement, or a new feature proposal, I'm all ears.
PS: Initial Order has to be open manually
Attached File(s)
QuoteDislikedUpdate 1:
I am happy to announce that despite the poor performance my strategy experienced in the past days, I present to you a significantly modified strategy that remains familiar to the first version of the DynamicHedge EA.
- **Opening a Random Initial Trade**: The EA opens a single random position (buy or sell) if there are no open positions marked by the EA for the specific symbol.
- **Hedging Based on Profit or Loss**:
- **For Profit**: If the initial or any subsequent trade closes in profit, the EA opens a hedge order at half the lot size of the just-closed trade. This new hedge order then becomes the reference trade for future decisions.
- **For Loss**: If a trade's loss exceeds a specified threshold, a hedge order is opened at twice the lot size of the losing trade without closing the losing trade.
- **Ensuring Only One Trade at a Time per Symbol**: Initially, only one trade should be open at a time per symbol. However, subsequent hedge orders are exceptions to this rule, as they are based on the outcomes of the initial or current reference trade.
- **Spread Control**: The EA checks the spread before opening any trade, ensuring it doesn't exceed a predefined maximum to avoid trading under unfavorable conditions.
- **Magic Number Use**: The EA utilizes a magic number to mark trades it manages, ensuring it only interacts with its own trades.
- **Manual Intervention Exception**: The strategy allows for manual closing of trades by the user. After such intervention, the EA's logic continues based on the next or remaining opened trade.
I know this new version is very basic, and the code needs further improvement. The way it handles the initial orders is not as refined as I intend it to be. It seems that ChatGPT is really at its limits; it struggles with such advanced tasks to implement into the EA. Therefore, I am asking all the MT4 pros to take a look and work some magic.
Thanks for your support.Attached File(s)
QuoteDislikedHello Everyone, chatgpt is speaking:
I'm excited to share a project I've been working on, named "DynamicHedge EA." This Expert Advisor aims to utilize market volatility by opening simultaneous buy and sell positions, managing them with a fixed stop-loss, and employing a trailing stop once break-even is reached. The goal is to capture small profits from both directions in a highly volatile market without using traditional indicators.
**Key Features of DynamicHedge EA:**
- Opens buy and sell positions simultaneously with a fixed lot size.
- Applies a fixed stop-loss to each position.
- Checks for a maximum allowable spread before executing trades.
- Implements a trailing stop mechanism once the position reaches break-even.
**Your Feedback:**
1. **Risk Management:** How can we improve our approach to dynamically adjust lot sizes based on account balance and risk tolerance?
2. **Spread Management:** Suggestions for handling rapidly changing spreads during high volatility periods.
3. **Trailing Stop Implementation:** Advice on optimizing the trailing stop logic to protect profits effectively.
4. **Error Handling:** Best practices for responding to order execution failures.
**Challenges and Considerations:**
- Ensuring the strategy complies with the regulations of different jurisdictions and brokers.
- Balancing the simultaneous buy and sell positions to avoid canceling out profits.
- Considering additional conditions for closing positions outside of the stop-loss and trailing stop criteria.
any suggestions, critiques, and improvements that could enhance the effectiveness of DynamicHedge EA. Your expertise and insights would be invaluable to refine our strategy.
Thank you in advance for your time and support.
the backtest looks fine![]()