Overview
This prompt aims to guide developers in creating an Expert Advisor for trading based on specific indicators. Programmers and traders will benefit by automating their trading strategies effectively.
Prompt Overview
Purpose: This Expert Advisor automates trading based on ADX and DI indicators for improved decision-making.
Audience: Designed for traders using MetaTrader 4 or 5 who seek to automate their trading strategies.
Distinctive Feature: It incorporates advanced calculations for ADX and DI, generating buy/sell signals based on defined thresholds.
Outcome: Users can expect a systematic approach to trading that minimizes emotional decision-making and enhances efficiency.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, Robotics & Automation
- 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 Expert Advisor (EA) trading robot based on the provided Pine Script v4 source code that calculates the Average Directional Index (ADX), Directional Movement Index Plus (DI+), and Directional Movement Index Minus (DI-).
The EA should utilize the logic from the source code’s calculations of ADX and DI to generate buy and sell trading signals. Implement the following detailed requirements:
1. Inputs:
– Length (len) for ADX and DI calculation (default: 14)
– Threshold (th) value for ADX signal (default: 20)
2. Indicators:
– Calculate the following:
– True Range
– Directional Movement Plus
– Directional Movement Minus
– Smoothed True Range
– Smoothed Directional Movement Plus
– Smoothed Directional Movement Minus
– DI+
– DI-
– DX
– ADX
– Follow the calculations as per the Pine Script.
3. Trading Logic:
– Generate a buy signal when:
– DI+ crosses above DI-
– ADX is above the threshold
– Generate a sell signal when:
– DI- crosses above DI+
– ADX is above the threshold
4. Order Management:
– Open a long position on a buy signal and close any short position.
– Open a short position on a sell signal and close any long position.
– Implement appropriate stop loss and take profit mechanisms if applicable.
5. Platform:
– Write the EA code in either MQL4 or MQL5, suitable for MetaTrader 4 or 5.
6. Comments:
– Include clear comments explaining:
– The implementation of ADX
– The DI indicators
– The trading logic
7. Order Position Management:
– Ensure management of order positions to prevent multiple simultaneous conflicting orders.
Produce well-structured, readable, and maintainable code that faithfully implements the original Pine Script logic in an automated trading EA.
# Output Format
Provide the complete EA source code as a single code block in MQL4 or MQL5 language, including comments that explain all steps.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste it into your preferred coding environment.
- Modify any specific parameters as needed for your strategy.
- Run the prompt to generate the EA code.
- Test the generated EA on a demo account.
- Adjust the code based on testing results if necessary.
Tips for Best Results
- Define Inputs: Set default values for Length (14) and Threshold (20) for ADX and DI calculations.
- Calculate Indicators: Implement True Range, DI+, DI-, and ADX calculations following the Pine Script logic.
- Trading Logic: Create buy signals when DI+ crosses above DI- with ADX above the threshold, and sell signals for the opposite condition.
- Order Management: Ensure proper opening and closing of positions, with mechanisms for stop loss and take profit if needed.
FAQ
- What is an Expert Advisor in trading?
An Expert Advisor is an automated trading system that executes trades based on predefined algorithms. - What does ADX measure in trading?
ADX measures the strength of a trend, indicating whether the market is trending or ranging. - How is a buy signal generated?
A buy signal occurs when DI+ crosses above DI- and ADX is above the specified threshold. - What is the purpose of stop loss in trading?
Stop loss limits potential losses by automatically closing a position at a predetermined 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.


