Overview
This prompt aims to guide programmers in creating a specific trading bot using MQL5 for MetaTrader 5. Programmers and traders will benefit from the structured approach to implementing a moving average strategy.
Prompt Overview
Purpose: This EA automates trading based on a 2 moving average strategy for efficient market entry.
Audience: Designed for traders using MetaTrader 5 who seek to implement automated trading strategies.
Distinctive Feature: It utilizes the 9 EMA and 36 EMA for precise entry and exit signals in the market.
Outcome: Users can expect systematic trading with predefined risk management and profit-taking strategies.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Consulting (Management, Strategy), Development Tools & DevOps, General Business Operations
- Techniques: Function Calling / Tool Use, Role/Persona Prompting, Structured Output
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- 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 an MT5 Expert Advisor (EA) trading bot using the MetaTrader 5 MQL5 language with the trade.mqh library. This EA should implement a 2 moving average trading strategy on the 5-minute timeframe, utilizing the 9 EMA and 36 EMA.
**Strategy Details:**
1. Indicators:
– Calculate the 9-period Exponential Moving Average (EMA).
– Calculate the 36-period Exponential Moving Average (EMA).
2. Entry Conditions:
– Long Entry:
– When the 9 EMA crosses above the 36 EMA (bullish crossover), wait for the price to retrace and touch the 9 EMA.
– Enter a long trade at the close of the candle that touches the 9 EMA after the crossover.
– Short Entry:
– When the 9 EMA crosses below the 36 EMA (bearish crossover), wait for the price to retrace and touch the 9 EMA.
– Enter a short trade at the close of the candle that touches the 9 EMA after the crossover.
3. Trade Management:
– Initial Take Profit (TP): Set to 50 pips from the entry price.
– Initial Stop Loss (SL): Set to 10 pips from the entry price.
– After the trade moves favorably and reaches a profit of 25 pips:
– Move the Stop Loss to the entry price (break-even) to secure the position.
**Implementation Requirements:**
– Use trade.mqh for trading operations.
– The EA must operate on the 5-minute timeframe.
– Implement proper risk management, adhering to the TP and SL rules described.
– Include necessary code comments explaining logic and calculations.
**Output Format:**
Provide the complete, well-structured MQL5 EA source code (.mq5) that fully implements the described strategy and can be compiled and run in MetaTrader 5.
**Notes:**
– Use appropriate functions to detect EMA crossover signals.
– Ensure the EA waits correctly for the price to touch the 9 EMA after crossover before entering.
– Adjust the SL only after the trade reaches 25 pips profit.
– Consider using appropriate pip-to-price conversions based on the instrument’s point size and digits.
– Include error checks for order placement and modifications.
**Response Format:**
Return the source code only, with no additional explanation.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Open your preferred code editor for MQL5.
- Paste the copied prompt into the editor.
- Implement the code according to the prompt’s specifications.
- Compile the code in MetaTrader 5.
- Run the EA on the 5-minute timeframe.
Tips for Best Results
- Set Up Indicators: Use iMA() to calculate the 9 EMA and 36 EMA on the 5-minute timeframe.
- Define Entry Conditions: Implement logic to check for bullish and bearish crossovers and wait for price to touch the 9 EMA.
- Manage Trades: Set TP to 50 pips and SL to 10 pips; adjust SL to break-even after 25 pips profit.
- Error Handling: Include checks for successful order placements and modifications to ensure robust execution.
FAQ
- What is the purpose of the 9 EMA in the strategy?
The 9 EMA helps identify short-term trends and potential entry points for trades. - How is a long trade initiated in this EA?
A long trade is initiated after the 9 EMA crosses above the 36 EMA and price touches the 9 EMA. - What happens after a trade reaches 25 pips profit?
The Stop Loss is moved to the entry price to secure the position at break-even. - What is the initial Stop Loss set to?
The initial Stop Loss is set to 10 pips from the entry price.
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.


