Back to Coding

Advanced MQL5 EA Generator

Prompt

Create an advanced MetaTrader 5 Expert Advisor (MQL5) with a target win rate of 89% or higher, implementing Smart Money Concepts (SMC), Price Action, Spha Strength Strategy, Order Blocks, Fair Value Gaps, Break of Structure, session filtering, adaptive risk management, and continuous trade cycling (close and reopen logic). The EA must be modular, well-commented, cleanly coded in MQL5, and designed to be manually extended later. --- ## Core Requirements - Trade only high-probability setups with multiple stacked confirmations before entry. - Dynamically adapt lot size based on market conditions and recent trade results. - Close trades early upon change in conditions and reopen if logic remains valid. - Strictly limit overtrading, enforce daily trade loss limits, and protect from high drawdowns. - The EA must only trade the following symbols: XAUUSD, US30, BTCUSD, USDJPY, and GBPUSD; it must not trade any others. ## Strategy Components 1. Indicators (Filters only, no standalone signals): - EMA 9 & EMA 20 (trend direction and pullbacks) - ADX (minimum threshold for trend strength) - ATR (volatility filter and stop loss/take profit scaling) - RSI (momentum and divergence confirmation) - Optional MACD histogram for directional bias 2. Smart Money Concepts Primary Logic: - Break of Structure (BoS): Require candle close beyond structural levels, filtering minor noise. - Order Blocks (OB): Detect last bullish/bearish candle before impulsive moves; entry only when price returns to OB aligned with higher timeframe bias. - Fair Value Gaps (FVG): Identify 3-candle imbalance zones; entries only allowed on price retracement into these zones; visually draw FVG boxes on chart. 3. Price Action Rules: - Trade only on strong impulsive candles with minimum candle body-to-wick ratio. - Avoid entries during choppy or low-volume periods. - Prefer rejection candles at OB/FVG zones. 4. Spha Strength Strategy: - Implement a scoring system (0.0 to 1.0) incorporating trend strength, volatility, structure clarity, and momentum. - Only trade setups with strength score ≥ 0.89 for enhanced win probability. ## Session & Trading Time Filters - Allow trades exclusively during London, New York, and London-New York overlap sessions. - Block trades during Asian sessions (except BTCUSD), low volatility times, and spread spikes. ## Order Lock & Overtrading Protection - Limit to one open trade per symbol. - Implement cooldown periods between trades per symbol. - Lock trading after reaching max daily loss threshold; unlock at start of the next trading day. ## Risk and Money Management - Dynamic lot sizing based on a user-defined base lot. - Increase lot size after wins (with controlled multiplier), decrease after losses. - Scale lot size factoring ATR, volatility, and Spha Strength score. - Enforce configurable max risk per trade (default 1-2%). - Enforce hard limit on max trades per day and max daily drawdown with shutdown. ## Trade Cycling & Management - If a trade closes early in profit and original conditions remain valid, reopen a new trade immediately with adjusted lot size. - Close trades early if conditions weaken. - Do not perform revenge trading. ## Code Structure (Approx. 400 lines total) - Section 1 (Lines 1–100): Core Setup — properties, metadata, input definitions (checkbox booleans for features), symbol validation, session filters, indicator initialization. - Section 2 (Lines 101–200): Market Analysis — structure detection, OB and FVG detection and chart drawing, trend & strength scoring (Spha logic). - Section 3 (Lines 201–300): Trade Logic — buy/sell entry conditions, risk and lot size calculations, order execution, stop loss and take profit placement. - Section 4 (Lines 301–400): Management & Safety — trade monitoring, early close logic, re-entry logic, daily limits enforcement, logging and debugging. ## Feature Checklist - Implement boolean flags for: - Structure confirmation - Valid Order Block - FVG tapped - Valid trading session - Spha Strength score >= threshold Only execute trades when all flags are true. ## Constraints - No repainting or future candle access. - Do not include unrealistic win-rate claims in comments. - Must compile without errors on MQL5 platform. - Fully commented for manual expansion. ## Output Format - Provide the complete, syntactically correct MQL5 Expert Advisor source code file. - Include comprehensive comments explaining each major block and logic component. - The code must be modular and well-structured according to the 4-section layout described. --- Follow all instructions carefully to produce a professional, institutional-style EA with a realistic high precision, low-frequency trading approach. The final code will serve as a master template for future manual customization and extensions.

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.