Overview
This prompt aims to create a sophisticated trading algorithm in MQL4 for MetaTrader 4, integrating advanced trading techniques. Programmers and traders seeking automated trading solutions will benefit from this comprehensive Expert Advisor.
Prompt Overview
Purpose: This Expert Advisor aims to enhance trading efficiency by integrating advanced strategies and real-time market analysis.
Audience: Targeted towards traders seeking automated solutions for high-frequency trading in the Forex market.
Distinctive Feature: It combines Fibonacci retracement, fractal detection, and volatility monitoring for optimized trade execution.
Outcome: The EA is designed to maximize profitability while minimizing risk through adaptive trading techniques and robust risk management.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Banking (Retail & Commercial), Development Tools & DevOps, Productivity & Workflow
- Techniques: Function Calling / Tool Use, Structured Output, Zero-Shot Prompting
- 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
You are to generate a fully integrated, high-performance Expert Advisor (EA) coded in MQL4 for MetaTrader 4 that implements all the advanced trading techniques and features outlined below.
This EA must:
– Compute Fibonacci retracement levels daily using the previous day’s high and low.
– Detect fractals and validate fractal wick lengths strictly before trade entries.
– Monitor volatility in real-time using:
– ATR
– Bollinger Bands width
– Spread analysis
– Optimize trade timing and frequency based on the above metrics.
– Implement hedging logic to maintain market neutrality by opening offsetting positions, neutralizing exposure automatically.
– Include institutional-style high-frequency scalping strategies such as:
– Mean reversion
– Order flow scalping
– Fibonacci and fractal signals
– Arbitrage opportunities
– Dynamically adjust trade frequency based on current market volatility:
– More trades during stable, low volatility periods
– Fewer trades during high volatility
– Use adaptive trailing stops that respond dynamically to evolving market conditions to protect profits and limit losses.
– Employ adaptive risk management ensuring losses do not exceed $0.50 per lot per trade by:
– Dynamically adjusting stop-loss levels
– Using pending orders
– Implementing trailing stops
– Setting immediate break-even when appropriate
– Use BuyStop/SellStop orders configured for ultra-fast market execution and automatic, intelligent order management.
– Guarantee stop-loss protection and intelligent trailing stop functionality for each position.
– Execute all trades in real-time without delays, suitable for live trading environments.
Implementation specifics include:
– Calculating Fibonacci retracements at each new trading day start based on prior day high and low.
– Strict fractal detection using wick length validation.
– Continuous volatility evaluation with ATR, Bollinger Bands width, and spread.
– Automatic hedging to maintain market neutrality.
– Integration of scalping and HFT strategies with:
– Mean reversion
– Order flow analysis
– Fibonacci/fractal signals
– Arbitrage
– Dynamic trailing stop adjustments based on volatility and price movement.
– Risk per trade capped at $0.50 per lot through dynamic stop-loss sizing.
– Robust handling of volatility spikes, market gaps, and spread widening.
– Efficient, clean, well-commented code adhering to MQL4 best practices for live trading performance.
– Configurability primarily for major currency pairs with flexibility to adapt to others.
# Steps
1. At each new trading day, compute and store Fibonacci retracement levels from the previous day’s high and low.
2. Continuously analyze incoming bars to detect fractal patterns, strictly validating wick lengths.
3. Calculate ATR, Bollinger Bands width, and spread continuously to assess volatility.
4. Dynamically modulate trade frequency depending on volatility metrics.
5. Implement hedging trades automatically to maintain market exposure neutrality.
6. Apply trailing stops that update dynamically with market moves.
7. Calculate and adjust stop-loss distances dynamically to ensure maximum risk per trade is $0.50 per lot.
8. Place, modify, and close trades instantly without delay.
# Output Format
– Provide a fully functioning MQL4 Expert Advisor source code file (.mq4).
– Ensure the source code is thoroughly commented, explaining:
– Calculation logic
– Trade signal generation
– Hedging
– Risk management
– Execution flow
– Structure code cleanly and modularly for readability and maintainability.
– Optimize and test code for robust performance in live trading conditions.
# Notes
– Prioritize efficient execution and resource management for instantaneous trade responsiveness.
– Implement safeguards for abnormal market conditions including:
– Gaps
– Sudden volatility spikes
– Spread widening
– Follow MQL4 best practices for order handling, memory management, and error checking.
Your response should be the complete MQL4 source code text implementing this Expert Advisor exactly following the above specifications, fully commented and production-ready for immediate live use.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste it into your MQL4 coding environment.
- Ensure the environment is set for MetaTrader 4 development.
- Run the code to generate the Expert Advisor.
- Test the EA in a demo account for performance.
- Deploy the EA in a live trading environment if satisfied.
Tips for Best Results
- Fibonacci Levels: Calculate daily Fibonacci retracement levels based on the previous day’s high and low for precise entry points.
- Fractal Validation: Ensure strict validation of fractal wick lengths before executing trades to enhance accuracy.
- Volatility Monitoring: Use ATR and Bollinger Bands to assess market volatility, adjusting trade frequency accordingly.
- Dynamic Risk Management: Implement adaptive stop-loss strategies to cap losses at $0.50 per lot, ensuring robust risk control.
FAQ
- What is the purpose of Fibonacci retracement levels in trading?
Fibonacci retracement levels help identify potential reversal points in the market based on previous price movements. - How does an Expert Advisor detect fractals?
An Expert Advisor detects fractals by analyzing price patterns and validating wick lengths for trade entries. - What is the role of ATR in trading strategies?
ATR measures market volatility, helping traders adjust their strategies based on current market conditions. - Why is hedging important in trading?
Hedging protects against adverse price movements, maintaining market neutrality and reducing overall risk exposure.
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.


