Back to Coding

Advanced Forex Scalper EA

Prompt

Create a complete MQL5 Expert Advisor (EA) that implements an advanced forex scalping strategy based on the detailed framework provided. The EA must include: - Multi-timeframe analysis using M1, M5, and M15 chart data. - Calculation and use of core indicators: EMA (8, 21, 50), RSI(14), MACD(12,26,9), Bollinger Bands (20,2), plus secondary indicators: Stochastic and ATR. - Automated detection and scoring of dynamic support/resistance (S/R) lines using criteria such as touch count, reaction strength, recency, and volume. - Candlestick pattern recognition for patterns including Doji, Hammer, Shooting Star, Engulfing, Pin Bars, and Inside Bars, particularly at significant S/R levels. - Entry logic employing a confluence scoring system requiring at least 4 out of 6 conditions met, incorporating EMA21 bias on M5, RSI thresholds, MACD histogram direction, candlestick patterns with volume confirmation, and pullbacks to EMA or S/R. - An exit strategy with: 250pt dynamic basket hedge mechanisms for price reversal, multiple partial profit targets based on ATR multiples and S/R, adaptive stop loss that is initially ATR-based, moved to break-even + 10 pips after first target, trailing stops using EMA8, exits, including a 30-minute max closure before major news events. - Robust risk management: position sizing based on 1% account risk adjusted by ATR volatility and signal strength; daily loss limits; consecutive loss tracking with position size reduction. - Session optimization to trade primarily during London and New York sessions, avoid trading around major news events, and reduce size during low-volatility periods. Technical requirements: - Modular and clear code structure with comprehensive inline comments explaining strategy components. - Configurable input parameters (e.g., indicator periods, risk percentage). - Use of standard MQL5 functions for indicators and trading actions. - Safeguards for invalid market data and unexpected conditions. - Handling of session-based trade filtering and news event avoidance. # Steps 1. Initialize indicators on M1, M5, and M15 timeframes. 2. Implement functions to detect and score dynamic S/R lines from recent price and volume data. 3. Build indicator calculation and candlestick pattern detection routines on M1 bars. 4. Develop confluence scoring logic for entry signals and enforce minimum score threshold. 5. Calculate position size dynamically incorporating ATR-based volatility and risk parameters. 6. Manage active trades with partial profit targets, hedging, adaptive stops, and time-based exits. 7. Integrate market session and news filters to enable/disable trading as appropriate. # Output Format Provide the entire fully commented MQL5 Expert Advisor source code as a single .mq5 file content string, properly formatted and indented for readability. # Notes - Prioritize correctness, clarity, and maintainability over performance optimizations. - The EA should be ready for future enhancements through its modular design. - Parameters like ATR periods, risk percent, and session times must be configurable inputs. - Include error handling to prevent trading in unreliable conditions. - The code must reflect the detailed scalping strategy's logic at every stage.

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.