Spezifikation
📑 Specification – Directional Grid EA (MQL5)
Name of the EA 7126.01
1. Purpose of the EA
A directional grid Expert Advisor that opens positions only in the chosen direction (LONG or SHORT), never using limit orders.
All positions are triggered exclusively via STOP orders (Buy Stop in bullish scenario, Sell Stop in bearish scenario).
2. Entry Logic
Bullish scenario (Direction = Long):
-
No BUY LIMIT orders allowed.
-
The first order is a BUY STOP placed at the defined price (InitialEntryPrice).
-
Each new BUY STOP is placed above the last executed order, spaced by GridSpacing points.
-
If the price goes down → no new orders are added.
-
New BUY STOP orders are only placed when the price moves back up and breaks above higher levels again.
Bearish scenario (Direction = Short):
-
No SELL LIMIT orders allowed.
-
The first order is a SELL STOP placed at the defined price (InitialEntryPrice).
-
Each new SELL STOP is placed below the last executed order, spaced by GridSpacing points.
-
If the price goes up → no new orders are added.
-
New SELL STOP orders are only placed when the price moves back down and breaks below lower levels again.
3. Lot Management (Pyramiding)
-
Initial lot size and money (Lot0) is calculated according to a risk percentage (RiskPercent) and money
Formula:
-
MaxLevels limits the total number of open positions.
4. Take Profit System
-
A global close occurs when the price pulls back by one standard deviation (σ) from the last reached level.
-
This means multiple positions (e.g., 4, 5 or 6) may be closed simultaneously on a 1σ pullback.
Example: If 6 positions are open and the price retraces 1σ → all positions are closed at market.
5. BreakEven (BE) Option
-
When the global profit reaches a defined threshold (BE_Trigger in $ or %), the global stop is moved to the weighted average price of the open positions (VWAP) + a buffer (BE_Buffer points).
-
At that stage, the risk becomes zero.
6. Stop Loss
-
A global stop loss must be configurable (SL_Points) and applied to all grid positions.
-
Option: individual stop loss per order (enabled/disabled by parameter).
7. User Parameters (Inputs)
-
Direction (Long/Short)
-
InitialEntryPrice (price of the first STOP order, otherwise current price)
-
RiskPercent (e.g., 1.0)
-
SL_Points (e.g., 200)
-
GridSpacing (points, e.g., 100)
-
PyramidFactor (e.g., 1.5)
-
MaxLevels (e.g., 6)
-
TP_Mode (1σ = standard deviation pullback)
-
BE_Trigger (net profit to activate BE, in $ or %)
-
BE_Buffer (margin in points above VWAP)
8. Numerical Example (LONG scenario)
-
Account = $16,000
-
RiskPercent = 1 % ($160)
-
SL = 200 points
-
GridSpacing = 100 points
-
PyramidFactor = 1.5
-
MaxLevels = 4
Lot0 = 160 ÷ 200 = 0.8 lots
Lot1 = 0.8 × 1.5 = 1.2 lots
Lot2 = 1.8 lots
Lot3 = 2.7 lots
→ Total ≈ 6.5 lots max
-
If 4 levels are reached and the price retraces by 1σ → all positions are closed.
-
If profit > BE_Trigger (e.g., $200) → SL is moved to VWAP + BE_Buffer.