Overview
This prompt aims to guide developers in creating a robust Expert Advisor for MetaTrader 5 using MQL5. Coders looking to automate trading strategies will benefit from the detailed requirements and structure provided.
Prompt Overview
Purpose: This Expert Advisor automates trading on MetaTrader 5, executing trades based on a defined strategy.
Audience: Designed for traders seeking automated solutions to enhance their trading efficiency and consistency.
Distinctive Feature: It incorporates moving averages and RSI with customizable parameters for tailored trading experiences.
Outcome: Users benefit from continuous market monitoring and robust risk management, ensuring stable trading operations.
Quick Specs
- Media: Text
- Use case: Arrangement, Content, Data analysis
- Techniques: Prompt Templates, Scratchpad Reasoning, Structured Output
- Models: ChatGPT, Claude, Gemini AI
- Estimated time: 5-10 minutes
- Skill level: Beginner
Variables to Fill
No inputs required — just copy and use the prompt.
Example Variables Block
No example values needed for this prompt.
The Prompt
Create a fully functional Expert Advisor (EA) for the MetaTrader 5 platform using MQL5 that operates continuously 24/7 without interruption.
**Requirements:**
– Monitor the market and execute trades at any time, ensuring round-the-clock operation.
– Implement a clear, well-defined trading strategy based on:
– Moving averages
– RSI on the 5-minute (M5) timeframe
– Include customizable parameters for:
– Moving average periods
– RSI period
– Entry and exit thresholds
– Integrate robust risk management features:
– Configurable stop loss
– Take profit
– Dynamic position sizing based on a user-defined risk percentage of account equity
– Ensure the EA handles runtime errors gracefully with:
– Error checking
– Recovery mechanisms to maintain stable and continuous operation without manual intervention
– Provide comprehensive in-code comments explaining:
– Key functions
– Trading logic
– Risk management
– Error handling
– Specify any dependencies or required platform settings for proper operation.
**# Steps**
1. Define the trading platform and use MQL5 language for MetaTrader 5.
2. Develop the trading strategy logic:
– Use two moving averages (e.g., fast and slow) and RSI indicator.
– Enter a long position when:
– Fast MA crosses above slow MA
– RSI is below an oversold threshold
– Enter a short position when:
– Fast MA crosses below slow MA
– RSI is above an overbought threshold
– Exit positions based on:
– Opposite signals
– Hitting stop loss / take profit
3. Implement continuous market data monitoring and order management in the EA’s OnTick event.
4. Add risk management:
– Allow user configuration of:
– Stop loss
– Take profit (in pips)
– Risk percent for position sizing
– Calculate position size dynamically based on:
– Current account balance
– Stop loss distance
5. Include robust error handling and recovery to manage common runtime issues (e.g., failed order send, connection loss).
6. Test and debug to verify stable 24/7 operation.
**# Output Format**
Provide the complete, well-structured, and fully commented MQL5 source code of the Expert Advisor, ready for compilation and deployment on MetaTrader 5.
**# Notes**
– All code sections should include descriptive comments to clarify logic and usage.
– Highlight features and techniques included to ensure stable, uninterrupted operation.
– Mention any external dependencies or special settings in comments at the start of the code.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste the prompt into your coding environment.
- Follow the outlined steps to develop the EA.
- Ensure to include comprehensive in-code comments.
- Test the EA for stable 24/7 operation.
- Compile and deploy on MetaTrader 5 platform.
Tips for Best Results
- Define Trading Strategy: Use two moving averages and RSI to determine entry and exit points based on market conditions.
- Implement Risk Management: Allow user-defined stop loss, take profit, and dynamic position sizing based on account equity.
- Error Handling: Integrate error checking and recovery mechanisms to ensure continuous operation without manual intervention.
- Comprehensive Comments: Include detailed in-code comments to explain functions, trading logic, risk management, and error handling.
FAQ
- What is an Expert Advisor in MetaTrader 5?
An Expert Advisor (EA) is an automated trading system that executes trades based on predefined strategies in MetaTrader 5. - How does the EA determine when to enter trades?
The EA enters trades based on moving average crossovers and RSI levels indicating overbought or oversold conditions. - What risk management features are included in the EA?
The EA includes configurable stop loss, take profit, and dynamic position sizing based on user-defined risk percentage. - How does the EA handle runtime errors?
The EA incorporates error checking and recovery mechanisms to ensure stable operation without manual intervention.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


