ArbitrageATR Recovery MT5
- Uzman Danışmanlar
- KO PARTNERS LTD
- Sürüm: 1.1
- Etkinleştirmeler: 10
Overview and Concept
The “ ArbitrageATR Recovery MT5 ” is designed to manage a complex trading strategy that combines grid trading, recovery orders, and correlation-based hedging. Its key innovations include:
- Dynamic Grid Sizing: Instead of using a fixed grid spacing, the EA automatically adjusts the grid distance using the Average True Range (ATR). This makes the system adaptive to market volatility.
- Multi-Order Recovery: When a position goes against the trade, the EA deploys additional recovery orders (with different magic numbers) to hedge and balance the exposure.
- Correlation Trading: The EA can optionally open positions on correlated symbols (for example, EURUSD, GBPUSD, USDJPY) to further offset risk.
- Greek-Based Hedging (Placeholders): While the core of the EA is based on price action and grid recovery, it includes placeholders for future expansion into delta, gamma, theta, and vega hedging.
This blend of grid and hedging methods makes the EA robust for volatile markets, and its dynamic grid adjustment ensures that it responds to changing market conditions.
Input Parameters and Customization
The EA provides a wide range of inputs so that the trader can finely tune its behavior:
-
General Trading Settings:
- Backtest mode, order open time, lot size, and magic numbers for base, recovery, and correlation orders.
- Options to close orders after a hedge is completed.
-
Recovery and Drawdown Settings:
- Modes for activating recovery (immediately, on drawdown, or after a defined start point).
- Drawdown type (percentage or absolute money drawdown).
-
Grid Trading Settings:
- The fallback static grid distance (in pips) and the dynamic grid distance is determined by multiplying the ATR value by an adjustable ATR factor.
- Multipliers for successive grid orders to scale the trade size.
-
Correlation Settings:
- Up to three correlation symbols can be specified along with directional settings (direct or reverse) to mirror the trade on correlated markets.
-
Take Profit (TP) and Stop Loss (SL) Settings:
- Options to delete TP/SL orders automatically, and rules to close partial lots depending on overall profitability or losses.
-
Time/Date Filters:
- Ability to restrict trading to specific times of day and specific days of the week.
-
Greek-Based Hedging Inputs:
- Parameters for delta, gamma, theta, and vega hedging (currently provided as placeholders for future expansion).
This high level of customization allows traders to adapt the EA to various market conditions and risk profiles.
Initialization
During initialization, the EA performs several tasks:
-
Symbol and Indicator Setup:
- It retrieves symbol properties (such as point size and digit count) and initializes the indicator handle (the Pivot Point SuperTrend, along with the ATR-related inputs).
-
Trading Conditions Setup:
- It sets the trade order filling method based on the symbol’s capabilities (FOK, IOC, or a fallback).
-
Multiplier Array and Correlation Activation:
- It initializes an array of multipliers for scaling grid orders and determines which correlation symbols are active based on the selected trade mode.
-
Balance and State Initialization:
- It records the starting balance and sets flags (such as whether the EA has already launched its first trade) so that it can decide when to start recovery actions.
Dynamic ATR-Based Grid Logic
A central innovation is the use of ATR to determine grid spacing dynamically:
-
GetDynamicGridDistance Function:
- This function uses the built-in iATR function to fetch the current ATR value for the symbol and multiplies it by the user-defined ATRFactor.
- If for some reason the ATR cannot be obtained, it falls back to using the static grid distance multiplied by the symbol’s point size.
-
Application in Order Placement and Chart Drawing:
- In CheckNextGrid() , the EA uses this dynamic grid value to decide whether the current market price has moved sufficiently from previous grid levels to justify opening an additional recovery order.
- Similarly, when drawing grid lines on the chart (if enabled), the dynamic grid distance is used so that the visual representation matches the trading logic.
This mechanism ensures that the grid adapts to current market volatility, making the EA more robust during both calm and turbulent market conditions.
Order Management and Recovery Logic
The EA contains several key functions that manage orders and implement the recovery strategy:
-
Base Order Placement:
- In backtest mode (or during live trading), an initial “base order” is placed at a predetermined time. This order forms the anchor for subsequent recovery and hedging trades.
-
Recovery Logic:
- Depending on the selected recovery mode (immediate, drawdown-based, or start-based), the EA monitors the account’s drawdown relative to the starting balance.
- When certain conditions are met (e.g., the drawdown exceeds a specified threshold), the EA creates hedge orders. The function CreateHedge is used to open hedge trades that offset the original position.
- Additionally, if certain profit or loss thresholds are met (TP/SL conditions), the EA may close recovery orders using functions such as CloseRecovery , CloseSomeLots , or CloseSomeLotsSL.
-
Grid Order Placement:
- The CheckNextGrid function evaluates whether new grid orders (either buy or sell) should be opened based on how far the price has moved relative to the lowest buy or highest sell order.
- Each new grid order is scaled using the multiplier array so that the trade size increases progressively with each grid level.
-
Partial Order Closure:
- The EA includes logic to partially close positions when TP/SL conditions are met, offering a risk management tool that helps lock in profits or limit losses gradually.
Correlation Trading
The EA also supports opening correlated trades:
- Correlation Order Execution:
- For each recovery order (buy or sell) on the primary symbol, corresponding orders may be placed on one or more additional symbols.
- The direction (buy or sell) for the correlation orders is determined by settings provided by the user (DIRECT vs. REVERSE).
- Multiple Magic Numbers:
- Separate magic numbers are assigned to correlation orders so that they can be managed or closed independently from the primary recovery trades.
This feature allows traders to potentially offset risk across correlated instruments.
Greek-Based Hedging (Future Expansion)
Although not fully implemented, the EA includes placeholders for advanced risk management:
- Delta, Gamma, Theta, and Vega Management:
- Functions such as ManageDeltaHedge , ManageGammaHedge , ManageThetaManagement , and ManageVegaHedge are stubs.
- These functions are intended to be extended with logic to monitor and adjust the portfolio’s exposure to various “Greeks” (i.e., risk measures common in options trading).
- This future expansion can further refine the EA’s risk management capabilities by ensuring that the overall portfolio remains within predefined risk thresholds.