Smart Grid Trader EA
- Experts
- AL MOOSAWI ABDULLAH JAFFER BAQER
- Version: 1.0
- Activations: 5
Please note: This Expert Advisor is provided as a flexible tool for strategy development. It has not been pre-optimized. It is designed for you to test, configure, and find the optimal settings that align with your personal trading strategy and risk tolerance.
Smart Grid Trader EA
The Smart Grid Trader is an Expert Advisor for MetaTrader 5 designed to implement a grid-based trading strategy. It provides a structured framework for placing trades at calculated intervals, offering a high degree of customization through its input parameters. This EA is intended for traders who understand grid mechanics and wish to explore and refine their own grid-based systems.
Core Features
-
Dynamic Grid Spacing: You can choose between a fixed pip distance for grid levels or a dynamic step based on the Average True Range (ATR) indicator. This allows the grid to adapt to changing market volatility.
-
Flexible Lot Management: The EA includes several money management options. You can use a fixed initial lot size, enable a Martingale multiplier to increase lot sizes at subsequent grid levels, or utilize a risk-percentage model to calculate lots based on your account balance and a defined stop loss.
-
Integrated Risk Control: A crucial safety feature is the maximum drawdown protection. You can set a maximum drawdown percentage for your account, and if this threshold is reached, the EA will automatically close all open positions to manage risk.
-
Grid-Based Exit Strategy: The primary exit logic is designed to close the entire basket of trades once a collective profit target (defined in your account's currency) is achieved. Alternatively, you can disable this feature and manage each trade with an individual Stop Loss and Take Profit.
-
Operational Control: The EA allows you to selectively enable or disable buy and sell orders. It also includes a time filter, giving you the ability to restrict trading activity to specific hours of the day.
-
On-Chart Visuals: For enhanced monitoring, the EA can display an information panel on your chart with key statistics like open orders, grid profit/loss, and drawdown. It also draws the grid levels directly on the chart, providing a clear visual reference for its operations.
This tool is available for $30, offering a functional foundation for you to build and test your grid trading approaches.
Expert Advisor Logic Explained
The Smart Grid Trader operates on a systematic logic designed to manage a grid of buy and sell orders. Here is a detailed breakdown of its mechanics.
Initialization and Setup
Upon starting, the EA first validates the essential input parameters, such as the grid step and lot size, to ensure they are logical. It then initializes key information about the trading symbol, including minimum volume, point size, and digits. The core of the strategy is a pre-defined grid of price levels. These levels are established above and below the current market price based on a "Grid Step" value. This step can either be a fixed number of pips set by the user or, if enabled, it can be dynamically calculated using the Average True Range (ATR) indicator. This allows the grid's spacing to automatically adjust to the market's current volatility.
Order Entry Logic
The EA does not place pending orders. Instead, it monitors the price on every tick. An order is triggered only when the price crosses one of the pre-calculated grid levels. For a buy order to be placed, the price on the previous tick must have been above a buy grid line, and the current price must be at or below that same line. Conversely, for a sell order, the price must cross a sell grid line from below to above. This "price cross" logic ensures that only one order is opened per level as the market moves through the grid. Trading is only permitted if it is within the user-defined hours and the account's drawdown is below the specified maximum.
Money Management and Lot Sizing
The volume for each order is determined by the CalculateLotSize function, which operates in one of three modes:
-
Fixed Lot: If Martingale and risk-based sizing are disabled, all orders use the specified initial lot size.
-
Martingale: If enabled, the lot size for each new order in the grid is increased by a set multiplier. For example, with a multiplier of 1.5, the lot sizes would progress from 0.01 to 0.015, then 0.0225, and so on.
-
Risk Percentage: If a stop loss in pips is defined, the EA can calculate a lot size such that a loss from the trade hitting its stop loss would equal a specified percentage of the account balance.
Before placing any trade, the EA checks if there is sufficient free margin to open the position.
Trade Management and Exit Strategy
The EA's primary exit mechanism revolves around a collective profit target. On every tick, the function CalculateGridProfitLoss sums the current floating profit and loss of all open positions managed by the EA. If this combined profit reaches the user-defined profit target in dollars, the CloseAllGridPositions function is triggered, and all open trades are closed simultaneously.
If the user disables this grid-based exit strategy, each trade is managed individually with its own Take Profit and Stop Loss values, which are set in pips when the order is placed.
Safety Mechanisms
The primary safety feature is the maximum drawdown control. The EA continuously monitors the account's equity and balance. If the current drawdown ((Balance - Equity) / Balance) reaches the user-defined maximum percentage, the EA will immediately close all of its open positions for that symbol and cease opening new ones until the condition is resolved. This is designed to protect the account from further losses during adverse market movements.
Feel free to explore other trading tools and Expert Advisors on my MQL5 seller profile: https://www.mql5.com/en/users/1218858/seller