# EMA 20/50 Trend-Following AI Crypto Trading Agent (MCP Script)

> Use `eterna.getEma()` with periods 20, 50, and 200 inside one `execute_code` call to rank trending perpetual pairs where price pulls back toward the 20 EMA inside an established 20 > 50 > 200 ribbon, then manage winners with `eterna.setTradingStop()`.

- Canonical URL: https://ai.eterna.exchange/strategies/ema-crossover-trend-agent
- Last updated: November 23, 2026
- Author: Eterna Quant & AI Team (Systematic Execution & MCP Playbooks)
- MCP endpoint: https://mcp.eterna.exchange/mcp

Crypto markets trend hard once breakouts clear range resistance. An EMA ribbon agent filters out choppy sideways pairs and keeps capital focused on the strongest directional movers.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| Indicators | EMA 20 / 50 / 200 | Computed server-side via getEma() |
| Stop Management | setTradingStop() | Trail stop beneath swing / EMA 50 |
| Best Pairs | BTC, ETH, SOL, TAO | Deep liquidity + clean trends |
| Perp Fees | 0.014% / 0.035% | Low drag on swing holds |

## 1. Runnable EMA Ribbon Pullback Scanner

### ema-trend-pullback.ts

```typescript
const symbols = ["BTCUSDT", "ETHUSDT", "SOLUSDT", "TAOUSDT", "SUIUSDT", "LINKUSDT"];
const setups = [];

for (const symbol of symbols) {
  const [t, ema20, ema50, ema200] = await Promise.all([
    eterna.getTickers({ symbol }),
    eterna.getEma({ symbol, interval: "60", period: 20 }),
    eterna.getEma({ symbol, interval: "60", period: 50 }),
    eterna.getEma({ symbol, interval: "60", period: 200 }),
  ]);

  const price = Number(t[0].lastPrice);
  const e20 = Number(ema20.value ?? ema20.latest);
  const e50 = Number(ema50.value ?? ema50.latest);
  const e200 = Number(ema200.value ?? ema200.latest);
  const distToE20Pct = Math.abs(price - e20) / e20;

  if (e20 > e50 && e50 > e200 && distToE20Pct < 0.008) {
    setups.push({ symbol, bias: "BULL_PULLBACK", price, e20, e50, e200 });
  } else if (e20 < e50 && e50 < e200 && distToE20Pct < 0.008) {
    setups.push({ symbol, bias: "BEAR_PULLBACK", price, e20, e50, e200 });
  }
}

return setups;
```

**Returns:** Trending markets currently pulling back within 0.8% of the 1h 20 EMA.

## 2. Entry & Trailing Stop Discipline

- Prefer pullback limit entries near EMA 20 instead of chasing candles extended 5% above the average.
- Invalidate the trade below EMA 50 and set `stopLoss` immediately on order placement.
- Once price moves +1.5R in favor, ask the agent to call `eterna.setTradingStop()` to trail the stop to breakeven.

## Frequently Asked Questions

### Can an AI agent trail stop-losses automatically on Eterna?

Yes. On scheduled check-ins, the agent reads `eterna.getPositions()` and `eterna.getEma()`, then updates the stop price with `eterna.setTradingStop()` when the trend advances.

## References & Primary Sources

- [Eterna SDK Reference](https://ai.eterna.exchange/sdk): Documentation for getEma and setTradingStop.

## Related Guides

- [RSI Mean-Reversion AI Crypto Trading Bot (Runnable MCP Script)](https://ai.eterna.exchange/strategies/rsi-mean-reversion-agent)
- [Multi-Coin MACD + RSI Momentum Scanner Agent (MCP Script)](https://ai.eterna.exchange/strategies/macd-momentum-scanner)
- [AI Trading for Solana (SOLUSDT) via Eterna MCP](https://ai.eterna.exchange/markets/sol)
- [Eterna MCP SDK Reference: All 30+ eterna.* Methods](https://ai.eterna.exchange/sdk)
