0bps

Strategy vault / Trend following

EMA Tracking Strategy

The EMA tracking strategy is a trend strategy that uses the EMA indicator to track trends. It calculates the EMA value of prices and combines it with a percentage band to determine price trends and generate trading…

Author
ChaoZhang
Complexity
Starter · 39 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

The EMA tracking strategy is a trend strategy that uses the EMA indicator to track trends. It calculates the EMA value of prices and combines it with a percentage band to determine price trends and generate trading signals.

Strategy Logic

The core indicator of this strategy is EMA. EMA stands for Exponential Moving Average, which is a trend tracking indicator. EMA calculates the current average price based on historical prices and the set time period. EMA also has the effect of smoothing prices.

The strategy first calculates the 50-period EMA value of prices as the main judgment indicator. Then based on a certain percentage of the EMA value, the upper and lower rails are set. Here it is set to ±0.3% of the EMA value. When the price breaks through the upper rail of the EMA, a buy signal is generated. When the price falls below the lower rail of the EMA, a sell signal is generated. This can track the trend changes within the EMA cycle.

Advantage Analysis

  1. Using EMA indicator to determine trends can avoid interference from price fluctuations
  2. EMA smooths prices and turns random volatility into clear trends for easy judgment
  3. Setting upper and lower rails of EMA forms a range band to reduce false signals
  4. The strategy logic is clear and easy to understand, and the parameters are relatively simple to adjust

Risk Analysis

  1. EMA indicator has lagging effect, signals are late at trend turning points
  2. Fixed percentage rails are prone to generating false signals during consolidation
  3. Backtest data overfitting risks, real price fluctuations may be greater
  4. No stop loss setting to control losses

Optimization Directions

  1. Add parameter optimization to find the optimal parameter combination
  2. Add stop loss mechanism to control maximum drawdown of the strategy
  3. Optimize the calculation method of upper and lower rails to reduce false signal rate
  4. Increase conditional filtering to avoid wrong entries during volatile markets
  5. Combine with other indicators for confirmation to improve strategy stability

Summary

The EMA tracking strategy has clear overall logic, judging price trends through EMA indicators and generating trading signals with range bands. The advantages are simple rules that are easy to understand and can avoid some noise. But there are also problems like limited tuning space, lagging signals, poor drawdown control, etc. Next steps could be improving it via means like combining multiple indicators, stop loss optimization, etc. to make the strategy more practical and stable.

Parameters

NameDefaultWhat it controls
v_input_1_close0Data Array: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_250EMA period
v_input_30.003Band %

Source Pine Script

/*backtest
start: 2023-01-17 00:00:00
end: 2024-01-23 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy(title="PingEMA50V.3 Piw", shorttitle="EMA50 Piw", overlay=true)

// input
src = input(title="Data Array",defval=close)
ema_period = input(title="EMA period", defval=50)
percent = input(title="Band %", type=float,defval=0.003)

// ema
ema50 = ema(src, ema_period)
plot(ema50, color=green)

// upper lower
upper = ema50 + (ema50*percent)
lower = ema50 - (ema50*percent)
plot(upper, color=blue)
plot(lower, color=blue)

// signal
buy = src > upper
sell = src < lower

// bar color
bcolor = buy ? lime : red
barcolor(color=bcolor)

// trade
if (buy)
    strategy.entry("long", strategy.long)
if (sell)
    strategy.close("long")

Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-24. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/EMA-Tracking-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open