Overview
This prompt aims to guide developers in creating a sophisticated Forex trading robot using Python and XML configuration. Programmers and traders will benefit by gaining a structured approach to automate trading strategies effectively.
Prompt Overview
Purpose: This Forex trading robot automates trading decisions using multiple strategies based on market indicators.
Audience: It is designed for traders and developers interested in algorithmic trading with Python and MetaTrader5.
Distinctive Feature: The robot supports configurable strategies through an XML file, enhancing flexibility and user customization.
Outcome: Users can expect efficient trade execution and robust risk management, improving their trading performance.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, Productivity & Workflow, Robotics & Automation
- Techniques: Decomposition, Plan-Then-Solve, 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 advanced Forex trading robot using Python that is configured via an XML file.
The robot must support multiple trading strategies:
– SMA crossover
– RSI
– Bollinger Bands
Additionally, it should implement robust risk management, including:
– Position sizing based on risk per trade
– Enforcement of a maximum daily trade limit
– Consideration of trading hours
– Trade logging
– Handling of basic error situations
Use the provided XML configuration structure as the source for input parameters. The robot must connect to MetaTrader5 to:
– Fetch historical data
– Calculate indicators (SMA, RSI, Bollinger Bands)
– Generate trading signals by combining the multiple strategies with weighted decisions
– Execute trades accordingly
It should also implement trailing stop management for open positions, ensure all logging is done properly to a file, and handle exceptions gracefully.
### Follow these steps:
1. Parse the XML configuration file, converting values to appropriate types (int, float, bool, string).
2. Initialize connection to MetaTrader 5; raise errors if initialization fails.
3. Fetch historical price data per the symbol and timeframe specified.
4. Calculate SMA (fast and slow), RSI, and Bollinger Bands indicators.
5. Generate buy/sell signals for each indicator and combine them into a composite decision.
6. Check current time against allowed trading hours.
7. Enforce daily trade limits.
8. Calculate position size based on account balance, risk per trade, and stop loss in pips.
9. Execute trades by sending orders to MetaTrader 5 with correct stop loss and take profit levels.
10. Implement trailing stop adjustments for open positions as configured.
11. Log all important events including errors, trade executions, and key decision points.
### Output Requirements:
– Provide a well-structured, complete Python program incorporating the above features.
– Use the following modules: MetaTrader5, pandas, numpy, xml.etree.ElementTree, and logging.
– Ensure the code is readable, modular, and includes comments for clarity.
– Handle edge cases such as failure to fetch data, account info, or symbol info by logging errors and avoiding crashes.
### Formatting Guidance:
– Format the Python code within markdown fenced code blocks for readability.
– Do not omit any part of the configuration or functionality described.
### Output Format
Provide the entire Python source code implementing the advanced Forex trading robot as described. Use clear docstrings and comments to explain each component. The code should be immediately usable given the appropriate environment and config.xml file as shown.
### Notes
– Assume standard pip installation availability for MetaTrader5, pandas, and numpy.
– The robot operates continuously or per invocation to check and execute trades.
– Use the provided XML structure exactly for all configuration parameters.
### Examples
No example input/output is required as the full code is the output.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste it into your preferred coding environment.
- Ensure you have required libraries installed: MetaTrader5, pandas, numpy.
- Create an XML configuration file as specified in the prompt.
- Run the Python program to execute the Forex trading robot.
- Monitor logs for performance and error handling.
Tips for Best Results
- XML Parsing: Use `xml.etree.ElementTree` to read and convert XML values to appropriate data types.
- MetaTrader5 Connection: Ensure a successful connection to MetaTrader 5 and handle initialization errors gracefully.
- Signal Generation: Combine SMA, RSI, and Bollinger Bands signals into a weighted decision for trade execution.
- Risk Management: Implement position sizing, daily trade limits, and trailing stop adjustments to manage risk effectively.
FAQ
- What programming language is used for the Forex trading robot?
The Forex trading robot is implemented using Python. - What strategies does the robot support?
It supports SMA crossover, RSI, and Bollinger Bands trading strategies. - How does the robot manage risk?
Risk management includes position sizing, daily trade limits, and trading hour considerations. - What logging features are included in the robot?
The robot logs important events, errors, trade executions, and key decision points.
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.


