Advanced Forex Trading Bot MQL5 EA for MetaTrader 5 (1)

Unlock advanced Forex trading with our expert MQL5 EA, designed for precision

Workflow Stage:
Media Type & Category:
Use Case
Save Prompt
Prompt Saved

Overview

This prompt aims to create a sophisticated MQL5 Expert Advisor for Forex trading, incorporating advanced strategies and risk management. Programmers and traders using MetaTrader 5 will benefit from this comprehensive script for automated trading.

Prompt Overview

Purpose: This EA aims to automate Forex trading by integrating multiple indicators and advanced risk management strategies.
Audience: It is designed for experienced traders and developers familiar with MQL5 and Forex market dynamics.
Distinctive Feature: The EA features adaptive lot sizing and dynamic TP/SL calculations, ensuring effective risk management for small accounts.
Outcome: Users will benefit from a robust trading tool that operates within specified market conditions and adheres to risk management protocols.

Quick Specs

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 a comprehensive, expert-level MQL5 Expert Advisor (EA) script for MetaTrader 5 that fully implements an advanced Forex trading bot as specified below.
### EA Requirements:
1. Technical Indicators Integration:
– Integrate multiple indicators:
– EMA
– RSI
– MACD
– Stochastic Oscillator
– Volume analysis
2. Risk Management:
– Implement adaptive risk management:
– Dynamic lot sizing as 1% of account balance
– Dynamic TP and SL, especially for minimum balances as low as $20
3. Time-Based Trading Restrictions:
– Confine trading to customizable New York session hours:
– `START_HOUR` to `END_HOUR`
### Market Sensing:
– Calculate the following:
– EMA with adjustable period (e.g., 20)
– RSI with adjustable period (e.g., 14) and defined thresholds:
– `OVERBOUGHT_THRESHOLD`
– `OVERSOLD_THRESHOLD`
– MACD histogram
– Stochastic Oscillator %K and %D
– Volume analysis
### Trade Execution Criteria:
– Buy Signals:
– Price is above EMA
– RSI is below `OVERSOLD_THRESHOLD`
– Bullish divergences on MACD and RSI
– Stochastic %K crosses above %D in oversold zone
– Volume supports upward momentum
– Sell Signals:
– Price is below EMA
– RSI is above `OVERBOUGHT_THRESHOLD`
– Bearish divergences on MACD and RSI
– Stochastic %K crosses below %D in overbought zone
– Volume confirms downward momentum
### Automatic Reversal Handling:
– Detect market reversals via divergences and indicator signals.
– Close existing positions and open reversed trades accordingly.
### News Event Management:
– Avoid opening new trade orders during scheduled news events affecting the symbol.
– Use `SymbolInfo()` or integrated MQL5 news APIs for detection.
### Global Variables Declaration:
Declare and initialize the following global variables at the top of the source file, clearly documented:
– `EMA_PERIOD` (integer, e.g., 20)
– `RSI_PERIOD` (integer, e.g., 14)
– `OVERBOUGHT_THRESHOLD` (float/integer, e.g., 70)
– `OVERSOLD_THRESHOLD` (float/integer, e.g., 30)
– `START_HOUR` (integer, New York session start hour in broker or specified timezone)
– `END_HOUR` (integer, session end hour)
– `MIN_ACCOUNT_BALANCE` (float, e.g., 20.0)
### EA Structure:
Organize the EA in a modular fashion with the following key lifecycle functions:
4. OnInit()
– Validate input parameters.
– Initialize and attach all indicators.
– Calculate starting lot size as 1% of current account balance.
5. OnDeinit()
– Properly detach indicators.
– Free all allocated resources.
6. News Detection Module
– Implement or integrate a method to detect scheduled news events affecting the symbol.
– Prevent trade openings during such news events within session hours.
7. OnTick() or Equivalent Compute Function
– Update indicator values upon each tick or new bar.
– Confirm current time is within defined session hours and no news event is active.
– Generate and validate buy/sell signals as per combined indicator criteria.
– Execute orders with proper lot sizing, adaptive SL, and TP.
– Handle existing trades and reversals.
8. Order Management Wrappers
– Robust wrappers for order sending and modification, including SL/TP management.
– Safe order closing functionality with error handling.
### Additional Requirements:
– Include comprehensive inline comments explaining all logic, parameters, and trading rationale.
– Provide guidance on optimal key parameters (e.g., EMA and RSI periods, thresholds) in comments.
– Ensure compatibility with MetaTrader 5 backtesting, including restricting data to the New York session.
– Support demo account operation.
– Apply robust error handling and input validations.
– Follow MQL5 coding standards and best practices.
### Output Format:
Provide a complete, well-structured `.mq5` source code file containing the fully implemented EA. Organize code modularly with distinct sections for:
– Initialization
– Indicator calculations
– Signal generation
– Order execution
– News detection
– Reversal handling
– Cleanup
Document all global variables and input parameters at the top of the file with clear, concise comments.
### Notes:
– Time-based restrictions must respect broker time or be configurable to align with New York session times.
– Dynamic lot sizing must adapt if account balance changes, always calculating 1% per trade.
– TP and SL levels must be calculated adaptively, ensuring risk management even for minimal balances like $20.
– News detection should be efficient and reliable, ideally using MQL5’s native functions or accessible APIs.
– Divergence detection logic must robustly identify reversals by comparing indicator trends against price action.
Deliver the expert advisor ready for immediate deployment and thorough backtesting under MetaTrader 5.

Screenshot Examples

How to Use This Prompt

  1. Copy the prompt provided above.
  2. Open your preferred text editor or IDE.
  3. Paste the prompt into a new document.
  4. Modify any specific parameters as needed.
  5. Save the document as an .mq5 file.
  6. Import the .mq5 file into MetaTrader 5.

Tips for Best Results

  • Use Modular Design: Organize your EA into distinct functions for initialization, signal generation, order management, and cleanup to enhance readability and maintainability.
  • Implement Robust Risk Management: Ensure dynamic lot sizing is calculated as 1% of the account balance, adapting to changes in balance to protect against significant losses.
  • Integrate News Filtering: Use MQL5’s news APIs to avoid trading during high-impact news events, ensuring trades are only executed in favorable market conditions.
  • Thoroughly Comment Your Code: Include detailed comments explaining the logic, parameters, and trading rationale to facilitate understanding and future modifications.

FAQ

  • What indicators are integrated into the MQL5 Expert Advisor?
    The EA integrates EMA, RSI, MACD, Stochastic Oscillator, and volume analysis.
  • How does the EA manage risk for trades?
    It uses dynamic lot sizing of 1% of the account balance and adaptive TP and SL.
  • What are the trading hours for the EA?
    Trading is confined to customizable New York session hours defined by START_HOUR and END_HOUR.
  • How does the EA handle news events?
    It avoids opening new trades during scheduled news events affecting the symbol using MQL5 APIs.

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Used Prompts

Related articles

AI Powered Web Development Portfolio with React PHP Bootstrap and DBMS Integration

Learn to build a dynamic portfolio that showcases full-stack development skills.

AI Wallet Finder Program with Authentication and Security

Ensure secure and user-friendly wallet tracking with reliable authentication features.

Determine Movie Ticket Cost by Age Conditional Logic Guide

Discover the perfect movie ticket price based on age with our easy-to-use

Create a 3D Robot Slum Simulation with Three.js for Developers

Embark on a neon-lit journey through Sector Zero's dystopian robot slum in