
Hey there, traders! Today, let’s dive into the world of automated trading with the MSLEA, a powerful EA (Expert Advisor) specifically designed for MetaTrader 4. This nifty tool is all about leveraging market structure highs and lows to help you make smarter trading decisions.
So, what does MSLEA do? It calculates the most recent local highs and lows, patiently waiting for breakout opportunities. If you’re interested in a deeper dive into local highs and lows, check out my article here.
How MSLEA Works
- **Long Trades**: If the price climbs above the local high (that’s when it crosses the green line), it’s time to go long.
- **Short Trades**: Conversely, if the price dips below the local low (crossing the red line), it’s time to short.
For an added layer of precision, you can set a distance in pips. For example, you might want the price to exceed the last high by 5 pips before entering a long position or drop 5 pips below the low for a short.
And don’t worry about getting caught in bad trades—MSLEA utilizes a trailing stop loss to protect your profits.
Key Parameters
- Level: Set this to 1 for the most recent local high/low. Higher values will use the minimum or maximum of the last n local highs/lows.
- Distance: Specify your desired distance in pips from the high or low.
- MaxTrades: The maximum number of trades allowed. A new trade will open only when the stop loss on your existing trades is secured.
- Lots: Specify the number of lots (0 means minimum lots required).
- Stop Loss: Use negative values to set a stop loss at a multiple of the broker's minimum (e.g., -3 for 30 pips).
- Take Profit: Same concept as stop loss for negative values.
- BreakEven: Set to adjust your stop loss to breakeven after winning x pips.
MSLEA can open as many positions as you like, as long as the stop loss for each is secure. This flexibility allows you to adapt to changing market conditions.
The EA is neatly organized into ea.mqh for better management, making the core code simple while separating order management tools. Feel free to customize your own strategies using ea.mqh!
Support the Author! If you find this code useful, consider showing your support to help keep it free for all. Check the comments in the .mq4 file for more details.

| Symbol | EURUSD (Euro vs US Dollar) | ||||
| Period | 15 Minutes (M15) 2010.11.18 00:00 - 2010.11.30 23:59 | ||||
| Model | Open Price (only for Expert Advisors that control bar openings) | ||||
| Parameters | MaxTrades=1; Level=2; Distance=11; Lots=1; Slippage=20; StopLoss=30; TakeProfit=0; TrailingStopLoss=true; BreakEven=20; Magic=12345; | ||||
| Bars in Test | 1857 | Ticks Modeled | 2712 | Modeling Quality | n/a |
| Errors in Chart Adjustment | 0 | ||||
| Initial Deposit | £10,000.00 | ||||
| Total Net Profit | £5,908.64 | Gross Profit | £6,028.64 | Gross Loss | -£120.00 |
| Profit Factor | 50.24 | Expected Payoff | £1,477.16 | ||
| Absolute Drawdown | £170.00 | Max Drawdown | £1,080.00 (7.83%) | Relative Drawdown | 8.18% (£1,040.00) |
| Total Trades | 4 | Winning Short Positions (%) | 1 (100.00%) | Winning Long Positions (%) | 3 (66.67%) |
| Profitable Trades (% of Total) | 3 (75.00%) | Loss Trades (% of Total) | 1 (25.00%) | ||
| Largest Profit Trade | £5,241.31 | Loss Trade | -£120.00 | ||
| Average Profit Trade | £2,009.55 | Loss Trade | -£120.00 | ||
| Maximum | Consecutive Wins (Profit in Money) | 3 (£6,028.64) | Consecutive Losses (Loss in Money) | 1 (-£120.00) | |
| Maximal | Consecutive Profit (Number of Wins) | £6,028.64 (3) | Consecutive Losses (Number of Losses) | -£120.00 (1) | |
| Average | Consecutive Wins | 3 | Consecutive Losses | 1 | |
Comments 0