: DTECH_BOT_V1 (MetaTrader 5 Trading Bot)

Automated Trading Architecture
Back to Gateway

1. Overview and Purpose

What is it?

DTECH_BOT_V1 is an automated Forex trading bot (also known as an Expert Advisor or EA) built for the MetaTrader 5 (MT5) platform. It is written in MQL5 (MetaQuotes Language 5).

What is it for?

The primary purpose of this bot is to automatically monitor the financial markets, identify trading opportunities based on a specific technical strategy, and execute trades (buy and sell orders) without requiring manual human intervention. It is designed with a "Safe Mode" and a "Beginner Safety Pack," making it accessible for new traders while still offering robust tools for developers and experienced users.

Who is it for?

---

2. How the Bot Works: The Core Strategy

The bot uses a combination of two popular technical indicators to make decisions:

1. EMA (Exponential Moving Average): Used to determine the overall Trend.

2. RSI (Relative Strength Index): Used to generate exact Entry Signals.

The Logic:

---

3. How the Bot Makes Requests (Trade Execution)

Whenever the bot decides to place a trade, it communicates with the MT5 Trade Server using the standard #include <Trade/Trade.mqh> library.

What happens during a request?

1. Condition Met: The EMA and RSI align perfectly.

2. Calculation: The bot calculates the exact lot size (trade volume) based on how much money is in the account and the user's risk percentage setting.

3. Execution: It sends a network request to the broker (e.g., IC Markets) asking to execute a "Market Order" at the best available current price (SYMBOL_ASK for Buys, SYMBOL_BID for Sells).

4. Safety Nets Attached: Along with the entry order, the bot simultaneously sends a Stop Loss (SL) request to limit potential losses, and a Take Profit (TP) request to automatically close the trade when a specific profit target is reached.

---

4. Key Features & Functionality Details

A. The Master Switch & Beginner Safety Pack

B. Risk and Money Management

The bot is incredibly careful with account balance, prioritizing capital preservation:

C. Trade Management & Trailing Stops

Once a trade is open, the bot manages it actively:

D. Environment Checks

Before any trade request is made, the bot checks the trading environment:

---

5. Detailed Code Breakdown (File-by-File Explanation)

Since the entire application is purposefully contained within a single file to ensure simplicity, here is the detailed breakdown of DTECH_BOT_V1.mq5:

1. `Inputs & Settings` (Variables)

2. `OnInit()` - The Setup Phase

3. `OnDeinit()` - The Cleanup Phase

4. `OnTick()` - The Main Engine (The Heartbeat)

1. Checks the InpMasterSwitch. If OFF, it stops immediately.

2. Calls UpdateStatus() to draw the dashboard on the screen.

3. Calls CheckEnvironment() to ensure spreads and hours are safe.

4. Checks if a Force Test Trade was requested and executes it if needed.

5. Calls ManagePositions() to update any Trailing Stops on currently open trades.

6. Counts how many trades are currently open. If it's less than InpMaxPositions, it calls CheckForEntry() to hunt for new trades.

5. `CheckEnvironment()` - The Security Guard

6. `CalculateLotSize()` - The Accountant

7. `ManagePositions()` - The Trade Manager

8. `CheckForEntry()` - The Sniper (Strategy Execution)

1. Copies the latest EMA and RSI data into memory arrays.

2. Determines the Trend: Is Close Price > EMA?

3. Looks for the RSI Crossover: Was the RSI below 30 on the previous candle, and is it now above 30?

4. If all conditions align, it calculates the lot size via CalculateLotSize().

5. It constructs the Trade Request: calculates the Ask Price, SL Price, and TP Price.

6. It fires the trade.Buy() or trade.Sell() command, passing a specific comment ("DTECH Machine Gun Buy/Sell") to uniquely mark the trade in the broker's system.

9. `DownloadHistory()` - The Data Sync

10. `UpdateStatus()` - The Dashboard

---

6. Installation & Usage Summary (For General Users)

1. Placement: The DTECH_BOT_V1.mq5 file should be placed in the MQL5\Experts folder of the MetaTrader 5 Data Directory.

2. Compilation: Open the file in MetaEditor and click "Compile" to generate the executable .ex5 file.

3. Execution: Drag the bot from the MT5 Navigator panel onto a chart (e.g., EURUSD).

4. Configuration: Check the "Inputs" tab to adjust the Risk Percentage, check the Master Switch, and customize Stop Loss/Take Profit settings. Ensure "Allow Algo Trading" is checked in MT5.

5. Monitoring: Look at the top left of the chart. The DTECH Dashboard will appear, showing live Equity, the current Trend, and the Master Switch status. If it says "Trading Active," the system is fully operational.

Visit Live Platform