Scalping MA Cross EA with Trend Filter
- Эксперты
- Edwin Baktian
- Версия: 1.0
📈 MA Cross 5/10 EA with Trend Filter
This Expert Advisor (EA) is an automated trading system based on a simple and proven Moving Average crossover strategy. It opens trades when a fast Moving Average crosses a slow Moving Average, and uses an optional Trend Filter to avoid trading against the main market direction.
Designed for beginners and intermediate traders, this EA focuses on clarity, stability, and disciplined trading rules.
✅ Main Advantages
✔ Simple and Reliable Strategy
Uses Moving Average crossover logic that is easy to understand and widely used by traders.
✔ Trend Filter for Safer Trading
Optional 200-period Trend Moving Average helps trade only in the direction of the main trend, reducing false signals.
✔ One Trade at a Time
Prevents overtrading by allowing only one active position per symbol and direction.
✔ New Bar Execution
Signals are processed only when a new candle forms, avoiding repeated entries on the same bar.
✔ Automatic Position Management
Automatically closes opposite positions before opening a new one.
✔ Time Filter (Optional)
Allows trading only during selected hours (for example: London or New York sessions).
✔ Fully Customizable
All important parameters can be adjusted to match your trading style and timeframe.
✔ Lightweight and Fast
Uses built-in MT5 indicators without heavy calculations.
⚙️ How It Works
BUY Signal
-
Fast MA crosses above Slow MA
-
(Optional) Price is above Trend MA
-
Time filter allows trading
-
No existing BUY position
SELL Signal
-
Fast MA crosses below Slow MA
-
(Optional) Price is below Trend MA
-
Time filter allows trading
-
No existing SELL position
Only one position is kept at a time. If an opposite signal appears, the EA will close the current position and open a new one.
⭐ Key Features
-
Moving Average crossover strategy (Fast MA & Slow MA)
-
Optional Trend Filter using long-period MA (default 200 EMA)
-
Optional Time Filter for trading sessions
-
Magic Number for trade identification
-
Custom trade comment
-
Works on any symbol and timeframe
-
No repainting logic (uses closed candles)
-
Stable execution on new bar only
-
Clean and well-structured code
🧾 Input Parameters
📊 Moving Average Settings
-
MA Fast Period – Period of the fast Moving Average (default: 5)
-
MA Slow Period – Period of the slow Moving Average (default: 10)
-
MA Shift – Shift value for Moving Average
-
MA Method – Type of MA (SMA, EMA, SMMA, LWMA)
-
Applied Price – Price used for MA calculation (Close, Open, High, Low, etc.)
📈 Trend Filter Settings
-
Use Trend Filter – Enable or disable trend filtering (true/false)
-
Trend MA Method – Method of Trend MA (default: EMA)
-
Trend MA Period – Period of Trend MA (default: 200)
-
Trend MA Applied Price – Price type for Trend MA
-
Trend MA Shift – Shift value for Trend MA
💰 Trade Settings
-
Lot Size – Fixed trading volume per trade
-
Magic Number – Unique ID to identify EA trades
-
Trade Comment – Custom comment for opened trades
⏰ Time Filter Settings (Optional)
-
Use Time Filter – Enable or disable time restriction
-
Start Hour / Start Minute – Trading start time
-
End Hour / End Minute – Trading end time
Supports sessions that cross midnight.
📌 Recommended Usage
-
Timeframes: M15, M30, H1
-
Symbols: Forex majors, Gold, Indices (with proper lot size)
-
Best used with Trend Filter enabled
-
Combine with proper risk management (lot size adjustment)
⚠️ Important Notes
-
This EA does not use Stop Loss or Take Profit by default (can be modified by user).
-
Always test on Demo Account before using on Real Account.
-
Market conditions may affect performance. Past results do not guarantee future profits.
🎯 Summary
MA Cross 5/10 EA with Trend Filter is a clean, simple, and effective automated trading system that:
-
Trades only on confirmed crossover signals
-
Filters trades by market trend
-
Avoids overtrading
-
Gives full control through input parameters
Perfect for traders who want a basic but disciplined algorithmic trading strategy in MetaTrader 5.
//--- Input parameters
input group "=== Moving Average Settings ==="
input int InpMAPeriodFast = 5; // MA Fast Period
input int InpMAPeriodSlow = 10; // MA Slow Period
input int InpMAShift = 1; // MA Shift
input ENUM_MA_METHOD InpMAMethod = MODE_SMA; // MA Method
input ENUM_APPLIED_PRICE InpMAAppliedPrice = PRICE_CLOSE; // Applied Price
input group "=== Trend Filter Settings ==="
input bool InpUseTrendFilter = true; // Use Trend Filter?
input ENUM_MA_METHOD InpTrendMAMethod = MODE_EMA; // Trend MA Method
input int InpTrendMAPeriod = 200; // Trend MA Period
input ENUM_APPLIED_PRICE InpTrendMAAppliedPrice = PRICE_CLOSE; // Trend MA Applied Price
input int InpTrendShift = 1; // Trend MA Shift
input group "=== Trade Settings ==="
input double InpLotSize = 0.1; // Lot Size (0 = auto calculate based on risk)
input int InpMagicNumber = 202401; // Magic Number
input string InpTradeComment = "MA Cross"; // Trade Comment
input group "=== Risk Management Settings ==="
input bool InpUseRiskManagement = true; // Use Risk Management?
input double InpRiskPercent = 1.0; // Risk % per trade (if InpLotSize = 0)
input double InpMaxRiskPercent = 5.0; // Maximum risk % of account
input int InpStopLossPoints = 0; // Stop Loss in points (0 = none)
input int InpTakeProfitPoints = 0; // Take Profit in points (0 = none)
input bool InpUseBreakeven = false; // Use Breakeven?
input int InpBreakevenPoints = 100; // Points to move to breakeven
input bool InpUseTrailingStop = false; // Use Trailing Stop?
input int InpTrailingStopPoints = 150; // Trailing Stop points
input double InpMinFreeMarginPercent = 20; // Minimum free margin % required to open trade
input group "=== Money Management Settings ==="
input bool InpUseMaxSpread = true; // Use maximum spread filter?
input int InpMaxSpreadPoints = 30; // Maximum spread in points
input bool InpUseMaxSlippage = true; // Use maximum slippage?
input int InpMaxSlippagePoints = 10; // Maximum slippage in points
input group "=== Time Filter Settings (Optional) ==="
input bool InpUseTimeFilter = false; // Use Time Filter?
input int InpStartHour = 0; // Start Hour
input int InpStartMinute = 0; // Start Minute
input int InpEndHour = 23; // End Hour
input int InpEndMinute = 59; // End Minute
