Overview
This prompt aims to guide developers in creating a versatile Expert Advisor for trading that adapts to various market conditions. Programmers and traders will benefit by gaining a structured approach to enhance their trading strategies and risk management.
Prompt Overview
Purpose: This Expert Advisor aims to enhance trading efficiency by adapting to varying market conditions dynamically.
Audience: The primary users are traders and developers looking to implement advanced trading strategies in their existing EA frameworks.
Distinctive Feature: It integrates a comprehensive market condition detection module that informs strategy selection and execution.
Outcome: Users can expect improved trade performance through tailored strategies and robust risk management practices.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, Machine Learning & Data Science, Productivity & Workflow
- 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 Expert Advisor (EA) for trading that dynamically adapts to any market conditions and seamlessly integrates into an existing EA framework. The EA must include the following core components:
1. Market Condition Detection Module:
– Detect Trending Markets:
– Use indicators such as ADX (Average Directional Index), Moving Average crossovers, or linear regression slope.
– Define a trending market as when ADX > 25 and a fast MA crosses above a slow MA.
– Identify Ranging Markets:
– Monitor Bollinger Band squeezes, low Average True Range (ATR), or price oscillating between established horizontal support/resistance zones.
– Detect Volatility Spikes:
– Identify sudden surges in ATR or anomalous candle sizes.
– Optional Analysis:
– Incorporate sentiment or volume analysis using tick volume divergence, news impact filters, or order book imbalance if data is available.
2. Strategy Selector:
– Implement a control block to route trade execution based on the detected market condition. For example:
“`
switch (marketCondition) {
case TRENDING:
executeTrendStrategy();
break;
case RANGING:
executeRangeStrategy();
break;
case VOLATILE:
executeBreakoutStrategy();
break;
default:
waitOrUseFallbackLogic();
}
“`
3. Strategy Modules:
– Trending Market Strategy:
– Use entries based on momentum breakouts, moving average crossovers, or pullbacks to dynamic support.
– Employ trailing take profit with momentum filters and stop losses below recent swing highs/lows.
– Ranging Market Strategy:
– Use oscillator signals (e.g., RSI, Stochastic) and reversal candle patterns at support/resistance.
– Set fixed take profits within range bounds and tight stop losses.
– Volatile/Breakout Strategy:
– Utilize candle size breakouts, Bollinger Band expansions, and news filters.
– Set wide stop losses and dynamic take profits based on ATR or momentum continuation.
4. Risk Management Layer:
– Apply dynamic position sizing that adjusts based on current volatility or confidence scores.
– Adjust stop loss and take profit levels using multi-timeframe expected pip gain calculations.
– Apply trade filters considering time-of-day, spread, slippage, and correlation with other instruments.
5. Continuous Re-Evaluation:
– Reassess the market condition every few candles.
– If the detected condition changes during an active trade, consider:
– Early exit
– Adjusting TP/SL levels
– Hedging/reversing the position
**Bonus: Multi-Timeframe Validation:**
– Confirm entry signals across multiple timeframes (e.g., M15, H1, H4) before executing trades to increase reliability.
# **Output Format**
– Provide structured pseudocode or detailed logic snippets illustrating how each module should function.
– Include code examples for key detection conditions and strategy selector logic.
– Describe the implementation approach for integrating the modules into an existing EA.
– Outline risk management formulas or algorithms clearly.
– Use clear bullet points and sections for readable organization.
# **Notes**
– Prioritize modularity so that each component can be maintained or enhanced independently.
– Ensure the EA can handle sudden market condition changes gracefully without generating conflicting trades.
– The solution should be adaptable to typical MetaTrader environments; however, language-agnostic pseudocode is acceptable.
– Include reasoning steps and explanations for indicator thresholds and strategy choices.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste it into your preferred coding environment.
- Analyze each core component outlined in the prompt.
- Implement the modules as described, ensuring modularity.
- Test the EA in a simulated environment for performance.
- Adjust parameters based on testing results and market conditions.
Tips for Best Results
- Market Condition Detection: Utilize ADX and moving averages to identify trending markets, while Bollinger Bands and ATR help spot ranging conditions.
- Strategy Selector: Implement a control block to execute specific strategies based on detected market conditions, ensuring adaptability to changes.
- Risk Management: Use dynamic position sizing and adjust stop loss/take profit levels based on volatility and multi-timeframe analysis for better risk control.
- Continuous Re-Evaluation: Regularly reassess market conditions and adjust trades accordingly, allowing for early exits or position adjustments when necessary.
FAQ
- What is the purpose of the Market Condition Detection Module?
It identifies market trends, ranges, and volatility spikes to adapt trading strategies. - How does the Strategy Selector function?
It routes trade execution based on detected market conditions like trending or ranging. - What strategies are used for trending markets?
Momentum breakouts, moving average crossovers, and pullbacks to dynamic support are utilized. - What is the role of the Risk Management Layer?
It adjusts position sizing, stop loss, and take profit levels based on volatility.
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.


