Advanced Forex Trading Robot
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), implement robust risk management including position sizing based on risk per trade, enforce a maximum daily trade limit, consider trading hours, perform trade logging, and handle basic error situations. Use the provided XML configuration structure as the input parameters source. The robot must connect to MetaTrader5 to fetch historical data, calculate indicators (SMA, RSI, Bollinger Bands), generate trading signals combining the multiple strategies with weighted decisions, and 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 must be a well-structured, complete Python program incorporating the above features, using MetaTrader5, pandas, numpy, xml.etree.ElementTree, and logging modules. Make sure 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. 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, 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.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.