Back to Coding

Aggressive Scalping EA MQL5

Prompt

Create an Expert Adviser (EA) in MQL5 that implements an aggressive scalping strategy based on the following detailed logic: - For a **buy** setup: - Detect when the current market price breaks above the high of the previous bullish candle. - Upon this breakout, place a **sell stop order** one tick below the breakout price. - When this sell stop order is triggered (activated), initiate a trailing stop that trails the price by one tick into profit. - The position must be closed immediately if the market moves two ticks against the trade (i.e., moves two ticks below the trailing stop for a buy setup). - The trailing stop should continue to follow the price until it is hit. - Once the trailing stop is hit and the market price moves above the original buy entry level, place a new sell stop order again one tick below the price, continuing the cycle. - For a **sell** setup: - Detect when the current market price breaks below the low of the previous bearish candle. - Upon this breakout, place a **buy stop order** one tick above the breakout price. - When this buy stop order is activated, initiate a trailing stop that trails the price by one tick into profit. - Close the trade if the market moves two ticks against the position. - The trailing stop should continue trailing until hit. - After the trailing stop is hit and the market price goes below the original sell entry, place a new buy stop order to repeat the cycle. Additional Requirements: - The EA must handle order placement, activation, trailing stop management, and closing of trades accurately in real-time. - Ensure the EA manages multiple trade cycles in a continuous loop according to the logic defined. - Implement appropriate safety checks to avoid code errors or unexpected behavior. - Optimize for aggressive scalping performance on relevant timeframes. # Steps 1. Identify the previous candle and check its bullish or bearish status. 2. Monitor for breaks above (for bullish) or below (for bearish) the previous candle's high/low. 3. Place the corresponding pending order (sell stop or buy stop) with one tick offset. 4. Upon order activation, monitor price movements to trail the stop by one tick. 5. Close the position if the price moves two ticks against the entry. 6. After closing, watch for the market to move beyond the original entry level and place the next pending order accordingly. 7. Repeat the cycle continuously. # Output Format Provide a complete, well-documented MQL5 Expert Adviser source code (.mq5) implementing the above scalping strategy, including comments explaining each critical section and logic. The code should be syntactically correct, ready for compilation and deployment on MetaTrader 5. Ensure all parameters, such as tick size or symbol properties, are dynamically obtained from the current chart context. # Notes - Use the market information functions to dynamically determine tick value and size. - Carefully handle order ticket management and check for order execution and modification results. - The EA must correctly handle stop order placement, trailing stop updates, and order close conditions within the OnTick() function or suitable event handlers. - Avoid hardcoding values; rely on dynamic symbol properties where applicable. - The trailing stop should move only one tick in profit increments, not more. # Examples No code snippets are provided here; the full working implementation is expected in the final 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.