Martin Boy
- Experts
- Jie Lin Wang
- 버전: 1.1
- 활성화: 5
Martin Boy – Dual-Directional Martingale Grid Trading Strategy Documentation
All parameters are based on the GBPJPY currency pair. Parameters for other currency pairs must be backtested separately. Historical maximum and minimum prices must be entered; otherwise, the strategy may result in one-sided trades or fail to trade.
This Expert Advisor (EA) implements a pure mathematical Martingale trading model designed for long-term stability and profitability:
25-Year Backtest Stability: The strategy is designed to survive extensive backtesting over decades without account blow-ups.
Market-Independent: Works independently of trends or ranging markets; no technical indicators or market condition filters are required.
Finite Risk Control: Uses a mathematically defined risk management framework to cap potential losses while allowing controlled exposure.
Adaptive Risk-Reward Scaling: Risk can be dynamically adjusted, and as risk tolerance increases, potential returns scale proportionally.
Fully Automated: The EA manages position sizing, risk scaling, and trade execution automatically, ensuring disciplined adherence to the strategy.
Key Advantages:
Purely mathematical and systematic, eliminating discretionary errors.
Can operate in any market condition.
Flexible risk-reward balance, adaptable to different account sizes and risk appetites.
Designed for robust long-term performance.
1. Strategy Overview
This strategy is a Dual-Directional Martingale Grid Trading System, designed specifically for MT5 Hedging Accounts. It captures trading opportunities during price fluctuations by combining Stochastic indicator signals with dynamic grid spacing calculations, and reduces average position cost through a Martingale position-adding mechanism.
Core Features
✅ Dual-Directional Trading: Supports simultaneous long and short grid trading
✅ Smart Grid: Dynamically adjusts grid spacing based on price and counterparty positions
✅ Dynamic Lot Size: Calculates trading lots intelligently based on account balance, price level, and position status
✅ Risk Control: Multiple risk limitation mechanisms, including price range and maximum lot restrictions
✅ Flexible Martingale: Adjusts the position-adding strategy based on market conditions
2. Strategy Principles
2.1 Basic Trading Logic
The strategy uses a grid trading + Martingale hybrid approach:
Initial Entry: Determined by the Stochastic indicator
Long signal: %K crosses above %D, and %D > buy zone (default 10)
Short signal: %K crosses below %D, and %D < sell zone (default 90)
Grid Position-Adding: When the price moves unfavorably, positions are added at preset grid intervals
Each additional lot increases by a multiplier (default 1.52)
Grid spacing adjusts dynamically according to the number of orders and price level
Take Profit Closing: When all positions in the same direction are profitable, they are closed once the target is reached
2.2 Grid Spacing Calculation
The strategy’s innovation lies in dynamic grid spacing, which considers:
Price Position Effect
Buy Grid Spacing = (Current Price / Historical High / Price Distance %) ^ Step Power × Base Step
Sell Grid Spacing = (Historical Low / Current Price / Price Distance %) ^ Step Power × Base Step
When the price approaches historical highs/lows, grid spacing narrows → more frequent trades
When the price is far from extremes, grid spacing widens → fewer trades
Step power (default 3.0) amplifies this effect
Order Quantity Effect
Actual Grid Spacing = Base Grid Step × (Grid Power - Price Power) ^ (Order Count × Opposite Side Coefficient) + Additional Step
As the number of orders increases, grid spacing gradually widens
Considers opposite-side positions to prevent excessive scaling in extreme conditions
2.3 Lot Calculation
Base Lot
Buy Base Lot = (Account Balance / BaseLotPercent / 1000) / (Current Price / Historical High / Price Multiplier %) ^ Lot Power + 0.01
Sell Base Lot = (Account Balance / BaseLotPercent / 1000) / (Historical Low / Current Price / Price Multiplier %) ^ Lot Power + 0.01
Base lot is proportional to account balance
Lot size decreases when price approaches extremes → risk control
Lot adjustments are smoothed using a power function
Position-Adding Lot (Martingale)
Initial Phase (first N orders): Base Lot × Initial Phase Multiplier (default 1.0)
Flexible Martingale Phase:
Opposite side strong: Previous Lot × Lot Multiplier × Opposite Side Multiplier (default 1.15)
Opposite side weak: Previous Lot × Lot Multiplier
2.4 Flexible Martingale Mechanism
The strategy uses three Martingale approaches based on counterparty positions:
Case 1: Initial Phase (Order Count ≤ Initial Threshold)
Use slower grid spacing (Initial Grid Slow × Base Grid Step)
Smaller lot multiplier (default 1.0)
Suitable for small fluctuations at market opening
Case 2: Opposite Side Strong (Opposite Lot ≥ Own Lot × Split Multiplier)
Narrower grid spacing (Opposite Side Step Discount, default 0.8)
Increased lot size (Opposite Side Multiplier, default 1.15)
Quickly balance positions and reduce risk exposure
Case 3: Opposite Side Weak (Opposite Lot < Own Lot × Split Multiplier)
Wider grid spacing (Split Threshold Offset, default 3.0)
Normal lot multiplier for continued scaling in favorable direction
2.5 Take Profit Mechanism
Buy TP Price = Last Buy Price + (Buy Order Count × TakeProfitPoints × Point Value)
Sell TP Price = Last Sell Price - (Sell Order Count × TakeProfitPoints × Point Value)
More orders → larger TP target
Triggered only when all same-direction positions are profitable
Closes all positions in that direction at once to lock profits
3. Key Parameters
3.1 Price Range
MaxPriceForBuy: 250 → no buys above this price
MinPriceForSell: 90 → no sells below this price
3.2 Base Trading Settings
BaseGridStep: 2.26 (range 2.0–3.8)
BaseLotPercent: 7500 (range 4500–125000)
LotMultiplier: 1.52 (range 1.50–1.75, >1.35)
GridPower: 1.232 (range 1.22–1.24, >1)
3.3 Initial Phase
InitialOrdersThreshold: 2
InitialGridSlow: 2.1
FirstPhaseMultiplier: 1.0
3.4 Flexible Martingale
AdditionalStep: 2.0
OppositeSideCoefficient: 2.2
OppositeSidePercent: 0.5
SplitThresholdOffset: 3.0
OppositeSideStepDiscount: 0.8
OppositeSideMultiplier: 1.15
3.5 Take Profit
TakeProfitPoints: 16 (recommended 10–70)
3.6 Limits
BaseLotLimit: 3.7
SplitMultiplier: 1.7
MaxTotalLots: 22 (recommended 6–18)
3.7 Main Unit
PriceDistancePercent: 0.7
PriceMultiplierPercent: 0.7
StepPowerMultiplier: 3.0
LotPowerMultiplier: 1.0
PriceRangePowerPercent: 100
3.8 Stochastic
StochasticPeriodK: 200
StochasticPeriodD: 20
StochasticSlowing: 20
StochasticBuyZone: 10
StochasticSellZone: 90
4. Risk Control
Only trade within preset price range
BaseLotLimit: restrict single-side lots relative to counterparty
MaxTotalLots: restrict total lots to prevent excessive scaling
PositionExpirationHours: 72000 → auto-close expired positions
Hedging account required
5. Trading Flow
5.1 Initialization
Verify account type (must be Hedging)
Initialize trading objects and indicators
Calculate base grid step and TP points
Create Stochastic indicator handle
5.2 Tick Handling
Check expired positions
Compute dynamic parameters (grid spacing, base lot)
Count current positions (long/short lots, orders, P/L)
Grid position-adding logic
Initial entry check via Stochastic signal
Take profit check
5.3 Trading Events
OnTradeTransaction: update last open price and lot
Reset variables when all positions closed
6. Strategy Advantages
Dual-Directional Profit
Smart Parameter Adjustment
Controllable Risk
Flexible Martingale
Fully Automated Execution
7. Usage Notes
⚠️ Must use a Hedging account
Adjust grid step, base lot %, and total lots according to volatility and account size
Test on demo accounts before live trading
Monitor total lots, price extremes, margin usage, and Stochastic signals
8. Technical Implementation
8.1 Key Functions
TotalPositions(), LotCheck(), RefreshRates(), iStochasticGet(), CloseAllBuy() / CloseAllSell()
8.2 Precision Handling
Automatically adjusts point values for 3- or 5-digit symbols
Normalizes lots according to broker requirements
9. Summary
This strategy is a highly intelligent dual-direction Martingale grid system, dynamically adjusting grid spacing and lot size to manage risk while aiming for stable profits. It is especially suited for sideways markets.
Key Advantages:
Smart dynamic parameter adjustment
Comprehensive risk control
Flexible Martingale strategy
Fully automated trading
Suitable For:
Sideways/oscillating markets
Hedging accounts
Traders with sufficient funds
Investors who can tolerate some drawdown
Strategy Version: 1.001
Document Updated: 2024
