Forex trading bot: expert advisors, sessions and the cost math
Forex was automated long before crypto existed — the “expert advisor” (EA) on MetaTrader has run currency strategies for two decades. But FX has its own quirks: it trades in sessions not 24/7 in the crypto sense, costs hide in the spread and overnight swap rather than a visible fee, and US retail forex is tightly regulated. This guide covers how forex bots execute, the session structure that decides when to trade, the true cost stack, and the rules that apply if you trade FX from the United States.
How a forex bot executes
A forex bot — usually called an expert advisor (EA) — watches a currency pair, evaluates a rule on each new candle, and places, modifies or closes orders through your broker. The logic is identical to a crypto bot's loop; only the venue and cost structure differ.
Two ways to build one
| Approach | Language | Best for |
|---|---|---|
| MetaTrader EA | MQL4 / MQL5 | Retail FX, huge ecosystem, broker-native |
| Python + broker API | Python | Quants, custom indicators, backtesting |
| cTrader / TradingView | cAlgo / Pine | Strategy prototyping, alerts |
A minimal MQL5 entry rule looks like this:
mql5 · ema_cross.mq5double fast = iMA(_Symbol,_Period,20,0,MODE_EMA,PRICE_CLOSE);
double slow = iMA(_Symbol,_Period,50,0,MODE_EMA,PRICE_CLOSE);
if(fast > slow && !PositionSelect(_Symbol))
trade.Buy(0.10); // 0.10 lot long on EMA cross-up
Whichever you pick, the signal logic is the same one you can validate on our backtester before wiring it into a live broker.
Sessions and pair selection
Forex liquidity rotates around the globe. Volatility — and therefore opportunity — concentrates in session overlaps.
The real cost stack: spread, swap, leverage
- Spread — the broker's markup between bid and ask; your real per-trade cost in FX.
- Swap / rollover — interest paid or earned for holding a position overnight. It can quietly erode a slow strategy.
- Leverage — FX brokers offer high leverage. It magnifies both gains and losses; a small adverse move can wipe an over-leveraged account.
Most blown forex accounts die from leverage, not from a bad signal. Size positions with the position calculator and keep risk ≤1% per trade regardless of how much leverage the broker offers.
US regulation you must know
In the United States, retail forex is regulated by the CFTC and the National Futures Association (NFA). Brokers must be registered, leverage is capped (e.g. 50:1 on majors), and the “no-hedging” / FIFO rules apply. Using an automated EA is legal, but the broker and the conduct must comply.
How to start
- Backtest the core signal on the backtester.
- Open a demo account on a regulated broker and run the EA for weeks.
- Account for spread + swap in your edge math, not just price moves.
- Go live tiny, with strict per-trade risk and a max-drawdown halt.
Frequently asked questions
What is a forex trading bot or expert advisor?
An expert advisor (EA) is an automated program — usually on MetaTrader 4 or 5 — that executes a currency-trading strategy without manual input. It evaluates rules on each candle and places, adjusts or closes orders through your broker.
Are forex trading bots legal in the US?
Yes. Automated forex trading is legal in the United States provided you use a broker registered with the CFTC and NFA and follow the applicable rules (leverage caps, FIFO). The automation itself is not the regulated part — the broker and conduct are.
Why do most forex EAs lose money?
Usually leverage and costs. High leverage turns a small adverse move into a blown account, and spread plus overnight swap eat slow strategies. Many marketed EAs are also curve-fit to past data and fail live. Backtest honestly and risk ≤1% per trade.
Can I build a forex bot without MetaTrader?
Yes. You can use Python with a broker's REST API, cTrader's cAlgo, or TradingView Pine alerts wired to an execution layer. The strategy logic is the same; only the platform and order API change.