AutomationUpdated: April 202615 min read

Expert Advisor MT4: Build Your First Trading Bot

Step-by-step guide to creating, testing, and deploying Expert Advisors on MetaTrader 4 for automated forex trading from India.

expert advisor mt4 guide

An Expert Advisor (EA) is an automated trading program that runs on MetaTrader 4 and executes trades based on pre-programmed rules without human intervention. EAs can monitor markets 24 hours a day, enter and exit trades with precise timing, and eliminate the emotional bias that plagues manual trading. Whether you want to automate a simple moving average crossover or a complex multi-timeframe strategy, this guide walks you through the entire process from concept to live deployment.

What an EA Can (and Can't) Do

An EA can: Monitor 50 charts simultaneously, execute trades in under 10ms, follow rules without emotion, backtest years of data in seconds, trade while you sleep.

An EA can't: Adapt to market conditions it wasn't programmed for, predict black swan events, compensate for a bad strategy. An EA that automates a losing strategy just loses money faster. The strategy must be profitable manually first.

3 Ways to Get an EA (Without Coding)

Option 1: MQL5 Marketplace (Buy Pre-Built)

The official marketplace has 10,000+ EAs ranging from free to $10,000. The problem: 95% are garbage. Marketing promises "500% annual return" but the backtest is curve-fitted to historical data and fails live.

How to filter:

  • Only consider EAs with live trading signals on MQL5 (not just backtest). A live signal shows real-time performance with real money.
  • Check the signal's drawdown. If max drawdown exceeds 30%, skip — it'll blow your account eventually.
  • Look for 6+ months of live data. Many EAs work for 2-3 months then stop. Time is the ultimate filter.
  • Price doesn't equal quality. A $30 EA with 12 months of live signal data is better than a $5,000 EA with only backtests.

Option 2: Zerodha Streak (No-Code, India-Specific)

If you trade NSE/BSE, Zerodha's Streak platform lets you build and deploy trading bots without writing code. You define conditions visually:

  • "When EMA 9 crosses above EMA 21 AND volume > 1.5x average → BUY Nifty Futures"
  • "When RSI > 70 AND price touches upper Bollinger Band → SELL"

Streak backtests against NSE historical data and deploys live to your Zerodha account. It's the easiest path from "I have a strategy idea" to "it's trading automatically." Limitation: only works with Zerodha and only on Indian markets.

Option 3: Build Your Own (MQL4/MQL5)

If you want full control, learn MQL4 (for MT4) or MQL5 (for MT5). Here's a minimal EMA crossover EA structure:

// EMA Crossover EA — Simplest possible structure
void OnTick() {
   double ema9  = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_CLOSE, 0);
   double ema21 = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 0);
   double ema9_prev  = iMA(NULL, 0, 9, 0, MODE_EMA, PRICE_CLOSE, 1);
   double ema21_prev = iMA(NULL, 0, 21, 0, MODE_EMA, PRICE_CLOSE, 1);

   // Buy signal: EMA9 crosses above EMA21
   if (ema9_prev < ema21_prev && ema9 > ema21) {
      OrderSend(Symbol(), OP_BUY, 0.01, Ask, 10, Ask-300*Point, Ask+500*Point);
   }
   // Sell signal: EMA9 crosses below EMA21
   if (ema9_prev > ema21_prev && ema9 < ema21) {
      OrderSend(Symbol(), OP_SELL, 0.01, Bid, 10, Bid+300*Point, Bid-500*Point);
   }
}

This is ~15 lines. A production EA with proper risk management, position sizing, and error handling is 200-500 lines. Resources to learn: MQL5.com documentation (free), Andrew Young's "Expert Advisor Programming" book (best MQL4 resource), and YouTube channels like "Toby Booth" for MQL5.

Backtesting: The Step Most Traders Skip

Before running any EA live, backtest it on at least 3 years of data:

  1. Open MT4/MT5 → Strategy Tester (Ctrl+R)
  2. Select your EA, symbol (EUR/USD), and timeframe (M5)
  3. Set date range: 2023-01-01 to 2026-03-31
  4. Set model: "Every Tick" (most accurate, slowest) or "Open Prices Only" (fast, less accurate)
  5. Run. Check: net profit, max drawdown, profit factor, number of trades.

What to look for:

  • Profit Factor > 1.3 — total wins ÷ total losses. Below 1.3 means the edge is too thin to survive real-world slippage.
  • Max Drawdown < 25% — if the backtest shows 40% drawdown, live will be worse (always is).
  • 1,000+ trades — less than 500 trades means the results aren't statistically significant.
  • Consistent equity curve — if the profit comes from 3 lucky months and the rest is flat/negative, it's curve-fitted.

Going Live: The 3-Phase Approach

  1. Demo (2 weeks): Run the EA on a demo account. Compare results to backtest. If demo performance is within 20% of backtest, proceed.
  2. Small live (1 month): Deploy on a real account with minimum lot size (0.01). Real spreads, real slippage, real psychology. If profitable after 50+ trades, scale up.
  3. Scale (ongoing): Increase lot size gradually (double every month while staying profitable). Never go from 0.01 to 1.0 in one jump.

Best Brokers for EA Trading From India

  • Exness: No restrictions on EAs. Supports scalping, grid, martingale. Free VPS for active traders. Raw Spread account has 0.0 pip spreads + $3.50/lot commission. Best for EA traders.
  • XM: Allows EAs but no scalping under 1-minute hold time on some account types. Good for longer-timeframe EAs (15-min+). $30 free bonus lets you test your EA with real money at zero risk.
  • IC Markets: Raw Spread accounts with 0.0 pip + $3.50/lot. cTrader platform has native algo trading (cAlgo) if you prefer C# over MQL.

For running your EA 24/7, pair your broker with a forex VPS — Exness offers a free one for active traders.

Risk Disclaimer: Automated trading carries additional risks including software bugs, connectivity issues, and over-optimization. Always test on demo before live trading. Past backtest results do not guarantee future performance.
R
Rajesh Kumar

Certified Financial Analyst & Asian Market Specialist

View full profile →

Affiliate disclosure: trading-zenith earns commissions when readers open accounts or use tools through links here. Indian residents must comply with FEMA + LRS regulations independently. Tracking is rel=sponsored.