Advanced Forex Trading Bot MQL5 EA for MetaTrader 5 Users

Unlock advanced Forex trading with our comprehensive MQL5 Expert Advisor for MetaTrader

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

Overview

This prompt aims to create a detailed MQL5 Expert Advisor script for Forex trading, incorporating advanced features and risk management. Programmers and traders will benefit from a ready-to-use, customizable trading bot that enhances their trading strategies.

Prompt Overview

Purpose: This MQL5 Expert Advisor aims to automate Forex trading using advanced technical indicators and risk management strategies.
Audience: The script is designed for Forex traders and developers looking to enhance their trading strategies with automation.
Distinctive Feature: It integrates multiple indicators, adaptive lot sizing, and dynamic trading restrictions for optimized performance.
Outcome: Users will receive a comprehensive, well-commented EA ready for deployment and backtesting in MetaTrader 5.

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 and professional MQL5 Expert Advisor (EA) script for MetaTrader 5 that implements an advanced Forex trading bot. This bot should integrate multiple technical indicators, adaptive risk management, and time-based trading restrictions as specified below.
### Core Requirements:
– Market Sensing Using:
– EMA (Exponential Moving Average)
– RSI (Relative Strength Index)
– MACD (Moving Average Convergence Divergence)
– Stochastic Oscillator
– Volume Analysis
– Adaptive Trade Execution:
– Automated buy and sell order placement based on combined indicator signals.
– Dynamic Lot Sizing:
– Calculated as 1% of the current account balance.
– Trading Restrictions:
– Strictly within customizable New York session hours (`START_HOUR` to `END_HOUR`).
– News Event Detection:
– Avoid trading during scheduled news events affecting the symbol using `SymbolInfo()` or MQL5 news APIs.
– Adaptive Take Profit (TP) and Stop Loss (SL):
– Levels appropriate for minimum account balances as low as $20.
– Automatic Reversal Handling:
– Detect market reversals through divergences and indicator signals, close existing positions on reversal, then open reversed trades accordingly.
### Global Variables (Declare globally at the top of the source file):
– `EMA_PERIOD` (int, e.g., 20)
– `RSI_PERIOD` (int, e.g., 14)
– `OVERBOUGHT_THRESHOLD` (float, e.g., 70)
– `OVERSOLD_THRESHOLD` (float, e.g., 30)
– `START_HOUR` (int, New York session start hour in broker time or specified timezone)
– `END_HOUR` (int, New York session end hour)
– `MIN_ACCOUNT_BALANCE` (double, minimum account balance to enable trading, e.g., 20.0)
### EA Lifecycle Functions Requirements:
1. OnInit()
– Validate all input parameters for acceptable ranges.
– Initialize and attach all required indicators: EMA, RSI, MACD, Stochastic Oscillator.
– Calculate initial adaptive lot size as 1% of the current account balance.
2. OnDeinit()
– Properly detach and release all indicator resources.
– Free any allocated memory/resources to prevent leaks.
3. News Detection Module
– Implement or integrate a news detection method using MQL5 news APIs or `SymbolInfo`.
– Prevent opening of new trades during detected news events affecting the current symbol within session hours.
4. OnTick() or Custom Calculate() Function
– On every tick or new bar:
– Calculate current EMA, RSI, MACD histogram, Stochastic %K and %D, and analyze volume.
– Confirm current time is within `START_HOUR` and `END_HOUR`.
– Confirm no active news event.
– Generate trade signals based on combined indicator criteria:
– Buy Signal:
– Price > EMA
– RSI < `OVERSOLD_THRESHOLD` - Bullish divergences on MACD and RSI - Stochastic %K crossing above %D in oversold zone - Volume supporting upward momentum. - Sell Signal: - Price `OVERBOUGHT_THRESHOLD`
– Bearish divergences on MACD and RSI
– Stochastic %K crossing below %D in overbought zone
– Volume supporting downward momentum.
– Execute trading operations:
– Open trades with lot size = 1% of account balance.
– Set SL and TP dynamically, compatible with minimum balances.
– Modify or close existing orders as necessary.
– Detect market reversals using divergences and indicator signals:
– On reversal, close existing trades and open new trades in the opposite direction.
5. Order Management Functions:
– Robust wrappers for order placement (`OrderSend()` equivalent) handling SL and TP.
– Safe order closing functions handling errors properly.
### Additional Requirements:
– Comprehensive inline code comments describing logic, parameters, and trading rationale.
– Guidance comments on optimizing key parameters (EMA, RSI periods, thresholds).
– Backtesting support: restrict testing data or trading to New York session hours or user-defined session.
– Support demo account operation for validation.
– Robust error handling and parameter validation throughout.
– Full compliance with MQL5 coding standards and best practices.
### Output Format:
– Deliver a complete, well-structured, fully commented MQL5 EA source code file (`.mq5`).
– Modular code organization:
– 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 clearly.
### Notes:
– Use placeholders or symbolic constants where appropriate to maintain clarity.
– Ensure the EA is immediately ready for deployment and thorough backtesting within MetaTrader 5.
Ensure the output is a single `.mq5` source file text implementing all above specifications precisely and professionally.

Screenshot Examples

How to Use This Prompt

  1. Copy the prompt provided above.
  2. Open your preferred code editor for MQL5.
  3. Paste the copied prompt into the editor.
  4. Modify any specific parameters as needed.
  5. Save the file with a .mq5 extension.
  6. Compile and test the EA in MetaTrader 5.

Tips for Best Results

  • Use Multiple Indicators: Integrate EMA, RSI, MACD, Stochastic Oscillator, and volume analysis for comprehensive market sensing.
  • Adaptive Lot Sizing: Set trade size dynamically at 1% of the current account balance to manage risk effectively.
  • Time-Based Trading: Restrict trading to specified New York session hours to align with market volatility.
  • News Event Avoidance: Implement news detection to prevent trading during significant economic events that may impact the market.

FAQ

  • What indicators are used for market sensing in the EA?
    The EA uses EMA, RSI, MACD, Stochastic Oscillator, and Volume Analysis for market sensing.
  • How is the lot size calculated for trades?
    Lot size is dynamically calculated as 1% of the current account balance.
  • What are the trading hours for the EA?
    The EA trades strictly within customizable New York session hours defined by START_HOUR and END_HOUR.
  • How does the EA handle news events?
    The EA avoids trading during scheduled news events affecting the symbol using MQL5 news 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