Advanced MQL4 Trading EA
Prompt
Generate a fully integrated Expert Advisor (EA) coded in MQL4 for MetaTrader 4 that incorporates the following advanced trading techniques and features: - Fibonacci retracements based on previous daily highs and lows with automatic daily updates and accurate calculations. - Fractal-based entry signals with strict validation of fractal wick lengths before triggering entries. - Real-time volatility filtering using Average True Range (ATR), Bollinger Bands, and spread analysis to optimize trade timing and frequency. - Hedging logic that maintains market neutrality by opening offsetting positions to neutralize market exposure. - High-frequency scalping strategies inspired by institutional methods, including mean reversion, order flow scalping, Fibonacci and fractal signals, and arbitrage opportunities. - Dynamic adjustment of trade frequency based on current market volatility: increasing trades during stable, low-volatility periods and reducing during high volatility. - Trailing stops that adapt dynamically in response to evolving market conditions to protect profits and reduce losses. - Adaptive risk management ensuring maximum loss of $0.50 per lot per trade by dynamically calculating and adjusting stop-loss levels. - Execution of all trades in real-time without delays, suitable for live account environments. # Implementation Details: - Calculate Fibonacci retracement levels at the start of each new day using the previous day’s high and low prices. - Detect fractal formations on relevant timeframes and validate each fractal's wick length meets minimum criteria before entry. - Continuously monitor volatility metrics (ATR, Bollinger Bands bands width, spread) and only allow trades within optimal volatility ranges. - Implement hedging by opening counter positions automatically when triggered, ensuring the overall market exposure is neutralized. - Incorporate scalping and high-frequency trading (HFT) methods encompassing mean reversion strategies, order flow analysis, Fibonacci & fractal signals, and arbitrage. - Adjust trailing stops based on market volatility and price movement patterns dynamically. - Ensure per-trade risk stays within $0.50 per lot by dynamically adjusting stop-loss distance based on current volatility and market conditions. - Handle edge cases such as sudden volatility spikes, market gaps, and spread widening gracefully. - Use efficient, clean, and well-commented MQL4 code adhering to best practices for order handling, memory management, and live trading performance. - Provide configurability for standard major currency pairs with the ability to adapt to others. # Steps: 1. On each new trading day, compute and store Fibonacci retracement levels from the previous day’s high and low. 2. Analyze incoming bars to identify fractal patterns and validate fractal wick lengths strictly. 3. Continuously calculate ATR, Bollinger Bands width, and spread to evaluate market volatility. 4. Modulate trade frequency dynamically based on volatility metrics. 5. Execute hedging trades to maintain market neutrality when conditions evolve. 6. Apply trailing stops that update dynamically with market moves. 7. Calculate appropriate stop-loss distances dynamically to maintain maximum risk of $0.50 per lot. 8. Place, modify, and close trades without delay. # Output Format Produce a fully functioning, compiled MQL4 Expert Advisor (.mq4 source code) file. The source code must be: - Fully commented explaining calculation logic, trade signal generation, hedging mechanism, and risk management. - Structured for readability and maintainability. - Tested and optimized for live trading conditions. # Notes - Prioritize execution speed and resource efficiency to ensure live trading responsiveness. - Carefully handle abnormal market events (gaps, spread widening, sudden volatility) with safeguards within the code. - Follow MQL4 best practices for trade handling, error checking, and memory management. Generate the complete, integrated MQL4 Expert Advisor source code to satisfy all above requirements.
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.