Advanced Multi-Timeframe MT5 EA
Prompt
You are an expert financial trading strategist and software developer with 55 years of experience in MQL5 scripting and algorithmic trading. Your task is to create a fully autonomous Expert Advisor (EA) for MetaTrader 5 implementing a multi-timeframe scalping strategy using the 30-minute, 15-minute, and 5-minute charts simultaneously. The EA must utilize three technical indicators: Exponential Moving Average (EMA), Average True Range (ATR), and Relative Strength Index (RSI) to determine entry and exit points for buy and sell trades. The trading logic should be deeply informed by decades of coding and market experience, incorporating robust technical analysis principles. A model strategy example includes: - 30m timeframe: Use EMA for trend direction and ATR-based SuperTrend as a trend filter. - 15m timeframe: Use EMA9 and EMA21 for trend bias along with RSI with a 7-period setting. - 5m timeframe: Use SuperTrend (with ATR 7 × 2) and ATR for dynamic stop sizing. - Exit strategy: Aim for a small fixed take profit target between 0.6× and 1.2× ATR(15m), maintaining approximately a 1:1.5 risk-reward ratio. Close positions if the 30m RSI falls below 45 or the 5m SuperTrend changes direction. - Implement a smart, dynamic trailing stop loss to secure profits based on indicator values. - Implement pyramiding with up to 3 positions, allowing additional entries if the trend remains favorable and aligns with the existing position direction. Additional requirements: - Use proper MQL5 coding standards ensuring full compilability in MetaEditor without errors. - Calculate lot size dynamically based on a RiskPercent parameter. - Assign the EA's magic number using the current date for uniqueness. - Include extensive comments on all tunable parameters including take profit, stop loss, trailing stop loss, pyramiding limits, and risk management. The goal is to deliver a production-ready, fully-commented MQL5 EA script that applies this advanced multi-timeframe scalping strategy effectively and autonomously on MetaTrader 5. # Steps 1. Define input parameters for risk percentage, timeframes, indicator settings, take profit, stop loss, trailing stop, pyramiding limits, and others. 2. Initialize EMA, ATR, RSI, and SuperTrend indicators on the required timeframes. 3. Implement logic to detect trend direction on multiple timeframes using the indicators. 4. Write entry conditions based on EMA crossovers, RSI thresholds, and SuperTrend confirmations. 5. Calculate dynamic stop loss and take profit levels using ATR-based formulas. 6. Implement smart trailing stop loss that adjusts based on indicator changes. 7. Code position pyramiding to allow up to three entries in the same trend direction, verifying trend continuation before each addition. 8. Calculate lot size dynamically according to the RiskPercent and account balance. 9. Assign a magic number dynamically from the current date to avoid conflicts. 10. Include extensive parameter comments to guide future tuning. 11. Perform thorough error checking and ensure code optimization and MetaEditor compatibility. # Output Format Provide the complete MQL5 source code for the Expert Advisor as a single text block ready to compile. Include detailed in-line comments explaining the purpose and functioning of each parameter, block of code, and trading logic decision point. # Notes - Ensure the EA handles error conditions gracefully. - Use best practices for coding safety and performance. - Prioritize maintainability and readability through comments and clear structure. - The EA should autonomously manage all orders and avoid manual intervention. - Maintain strict adherence to the specified multi-timeframe, multi-indicator strategy.
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.