Overview
This prompt aims to guide programmers in enhancing an Expert Advisor for MetaTrader by adding a third Moving Average for trailing stop loss management. Developers and traders using MetaTrader will benefit from improved trading strategies and automated risk management.
Prompt Overview
Purpose: The goal is to enhance the existing Expert Advisor by adding a third Moving Average for improved trailing stop loss management.
Audience: This modification is intended for developers familiar with MQL4/MQL5 and MetaTrader trading strategies.
Distinctive Feature: The new Moving Average will operate independently, solely influencing the trailing stop loss without altering existing entry or exit signals.
Outcome: The modified EA will dynamically adjust the trailing stop loss based on the third Moving Average, ensuring optimized trade management.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, Productivity & Workflow
- Techniques: Role/Persona Prompting, Self-Critique / Reflection, 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
Assist in modifying an existing Expert Advisor (EA) for MetaTrader to add a third Moving Average (MA) specifically for managing a trailing stop loss (SL).
**Details:**
– Understand the current EA structure and its use of Moving Averages.
– Implement an additional (third) Moving Average that will be dedicated solely to the trailing stop loss mechanism.
– Ensure that the trailing stop loss adjusts dynamically based on the third MA.
– Maintain code clarity and comment on the new additions appropriately.
– Confirm that the modified EA compiles and runs without errors.
**Steps:**
1. Analyze the existing EA code to identify:
– Current Moving Averages
– Trailing stop loss logic
2. Introduce a third Moving Average with the appropriate parameters.
3. Integrate the third MA into the trailing stop loss calculation and adjustment.
4. Test the EA to verify that the trailing stop loss behaves as intended with the new MA.
5. Provide commented code snippets illustrating the changes.
**Output Format:**
– Provide clear code examples showing the implementation of the new third MA.
– Include comments explaining how the third MA is utilized for the trailing stop loss.
– If applicable, provide explanations or instructions for configuring the new MA settings.
**Examples:**
“`
// Example snippet adding a third MA
double ma3 = iMA(NULL, 0, ma3_period, 0, MODE_SMA, PRICE_CLOSE, 0);
// Use ma3 to set the trailing stop loss
“`
**Notes:**
– Ensure compatibility with the existing EA logic.
– The third MA should function independently and not affect existing MAs used for entry or exit signals.
– The EA is assumed to be written in MQL4/MQL5; specify if needed.
**Output Format:**
Provide code snippets with comments and explanations in plain text.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste the prompt into your coding environment.
- Follow the detailed steps to modify the EA.
- Test the EA for functionality and error-free compilation.
- Review and comment on the new code additions.
Tips for Best Results
- Analyze Existing Code: Review the current EA to identify how Moving Averages are implemented and where the trailing stop loss logic resides.
- Add Third Moving Average: Introduce a new variable for the third MA, ensuring it uses the desired parameters for calculation.
- Integrate into Trailing Stop Logic: Modify the trailing stop loss calculation to utilize the value of the third MA, ensuring it adjusts dynamically as market conditions change.
- Test and Validate: Run the modified EA in a demo environment to confirm that the trailing stop loss functions correctly with the new Moving Average without introducing errors.
FAQ
- What is an Expert Advisor in MetaTrader?
An Expert Advisor (EA) is an automated trading system that executes trades based on predefined strategies in MetaTrader. - How do Moving Averages assist in trading?
Moving Averages smooth price data to identify trends and potential entry or exit points in trading. - What is a trailing stop loss?
A trailing stop loss is a dynamic stop loss that adjusts with the market price to protect profits. - Why add a third Moving Average for trailing stop loss?
A third Moving Average can provide additional confirmation for adjusting the trailing stop loss effectively.
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.


