Code Overview
an Expert Advisor (EA) developed for the MetaTrader 4 (MT4) platform, designed for automated forex trading. The EA implements a grid trading strategy based on price movements, opening trades when price fluctuations meet specific intervals. It incorporates risk management features such as stop-loss, take-profit, and trailing stop mechanisms. Written in MQL4, the code uses Chinese parameter names to facilitate configuration for Chinese-speaking users.
Main Features
Trading Logic:
Mode 0: Fixed lot size (初始手数).
Mode 1: Geometric lot progression based on 手数倍增因子 (Lot Multiplication Factor, default 1.08).
Mode 2: Adjusts lot size based on historical trade outcomes (increases after losses, resets after profits).
Grid Trading: The EA opens trades (buy or sell) when price movements reach the 交易间隔点数 (Trade Step Points, default 10 points), with a maximum of 最大交易数 (Max Trades, default 100) open trades.
Entry Conditions: Trade direction is determined by comparing the closing prices of the last two bars. For example, if the previous bar’s close is higher than the one before it, a sell order is opened.
Lot Management: Supports three money management modes (资金管理模式):
Risk Management:
Stop-Loss and Take-Profit: Each trade can have a 止损 (Stop Loss, default 0) and 止盈 (Take Profit, default 10 points).
Trailing Stop: When 启用追踪止损 (Enable Trailing Stop) is true, the EA activates a trailing stop after the price moves beyond 追踪止损启动点数 (Trailing Start), with a step size of 追踪止损步长 (Trailing Step).
Equity Protection: If floating losses exceed 净值保护百分比 (Equity Profit Percent, default 20%), the EA closes all trades.
Timeout Protection: Trades are closed if they exceed 超时保护小时数 (Timeout Profit Hours).
Time Filters:
Hour-Based Trading: When 按小时交易 (Trade By Hours) is true, the EA only trades between 交易开始小时 (Trade Start Hour) and 交易结束小时 (Trade End Hour).
Time Filter: When 启用时间过滤 (Enable Time Filter) is true, the EA restricts opening or closing trades based on the time range.
Account Verification:
The EA checks the account number (G_acc_number_84). If the current account does not match, trading is halted with a notification.
Information Display:
The f0_8 function displays account details (e.g., balance, equity, spread) and server/GMT time on the chart.
Key Functions
OnInit: Initializes the EA, setting lot precision and point adjustment factor (Gi_440, for 5-digit or 3-digit brokers).
OnTick: Core trading logic, executed on each price tick, handling entry/exit conditions and trailing stops.
f0_1: Closes buy or sell orders.
f0_11: Calculates lot size for new trades based on the money management mode.
f0_12: Sends trade orders, supporting market orders (buy/sell) and pending orders (limit/stop).
f0_15: Implements trailing stop logic, dynamically adjusting stop-loss levels.
f0_8: Updates chart display with account and market information.
Usage Instructions
Installation:
Save the code as Volcano8FX_Chinese.mq4 in the MQL4/Experts directory of MT4.
Ensure the stdlib.ex4 library is in the MQL4/Libraries directory.
Compile the code in MetaEditor (F7) and check for errors.
Configuration:
Drag the EA onto an MT4 chart to open the parameter settings window.
Adjust parameters such as 初始手数 (Initial Lot), 止损 (Stop Loss), 止盈 (Take Profit), and 交易间隔点数 (Trade Step Points).
Set G_acc_number_84 to 0 or match your account number to bypass account restrictions.
Testing:
Test the EA on a demo account to observe its trading behavior and risk management.
Monitor the MT4 “Experts” or “Journal” tab for logs to diagnose issues.
Notes
Risk: Grid trading can lead to significant losses in trending markets. Use conservative settings for 初始手数 and 手数倍增因子.
Account Restriction: If G_acc_number_84 is not 0, the EA may be limited to specific accounts.
Library Dependency: The stdlib.ex4 library is required for the ErrorDescription function. Ensure it’s available.
Parameter Optimization: Tailor parameters to the traded symbol (e.g., EURUSD) and timeframe (e.g., M15).
下载链接付费查看哦!
支付宝扫一扫打赏9元查看