AdaptiveTrend EA
Prompt
Create a fully functional MQL4 Expert Advisor (EA) for MetaTrader 4 that implements an adaptive trading strategy dynamically responding to market trends (uptrend, downtrend, sideways). The EA must meet the following detailed specifications: - Refresh Rate: 1 millisecond (constantly updating and monitoring the market); - Activate trading only after the specified local time: 2024.02.01 01:00:00; - Initial Lot size: 0.1 lots; - Place Pending Orders (PO) at 200 points distance from current price; - Lot Multiplier ratio: 1.235 between total Buy lots to Sell lots; - Maximum open positions capped at 10; - Target Take Profit (TP) of 9000 USD and Stop Loss (SL) of 3000 USD in USD terms; - Partial Close Profit threshold set at 5000 USD to partially close positions; - Delay at least 3 seconds before starting the next order after one closes or opens; Requirements: 1. Market Condition Awareness: - Continuously loop and identify optimal premium prices to sell and optimal discounted prices to buy. - Execute additional orders during market retests, pullbacks, or when prices approach equilibrium/base prices in demand & supply zones. 2. Profit Protection Strategy: - For orders reaching sufficient profit, move SL to break-even plus spread (20 points) and include commissions. - If this SL is hit, open new orders at better prices than the previous closed orders. 3. User Interface: - Add a "Close All Orders" button in the MT4 terminal to allow the user to immediately close all open trades. 4. Trailing Stop Mechanism: - Implement a dynamic trailing stop that moves SL gradually, maintaining an optimal distance from current price to maximize gains while preventing premature stop outs. 5. Take Profit Adjustments: - Dynamically adjust TP levels targeting high probability zones based on current market momentum. 6. Equity Protection: - Monitor account equity relative to balance, and immediately close all positions if equity drops by 5% or a user-defined threshold. 7. Martingale Strategy: - Apply a Martingale approach when market conditions justify it for high probability zones, with configurable adjustable order distance (default 25 points). 8. Flexible Trading Operations: - Support opening both buy and sell orders based on real-time market conditions and user-configured strategies. Dashboard Display: - Show Active Time (activation time); - Display remaining time until the EA becomes active formatted as hh.mm.ss; - Show the Initial Lot size; - Current floating position profit/loss in USD; - Total accumulated Take Profit since activation in USD; - Number of Take Profit orders not yet fulfilled. Implementation Steps: 1. Define all necessary EA input parameters and settings within MetaEditor 4: - User-customizable options including order comments, magic numbers, lot sizes, martingale distances. 2. Program the lot size logic that multiplies buy and sell lot sizes maintaining the specified ratio. 3. Implement order management: - Close all orders functionality. - Partial profit closures when profit thresholds are met. 4. Design and code the on-screen dashboard with clear visual display of key EA metrics. 5. Develop continuous logic for detecting optimal entry/exit points leveraging retest, pullback, and demand/supply zone analysis. Output Format: Provide the complete MQL4 source code for the Expert Advisor in a single file. The code must be extensively commented, clearly explaining the purpose and function of each major section, variable, and logic block to facilitate understanding, compilation, and backtesting within MetaEditor 4. Ensure the code is ready to run immediately upon compilation without missing dependencies or errors.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.