0bps

Strategy vault / Trend following

Multi Period EMA Crossover Quantitative Trading Strategy

This article introduces a quantitative trading strategy based on the crossover points of Exponential Moving Averages (EMA) over three different periods. The strategy aims to utilize EMA crossovers to identify…

Author
ChaoZhang
Complexity
Intermediate · 67 lines
Parameters
9
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This article introduces a quantitative trading strategy based on the crossover points of Exponential Moving Averages (EMA) over three different periods. The strategy aims to utilize EMA crossovers to identify long-term and short-term trends in the stock market for effective trading decisions.

Strategy Principle

The strategy employs EMAs of three different periods: 10-day, 100-day, and 200-day. Buy or sell signals are generated based on the direction of the crossover when the short-period EMA (10-day) crosses the longer-period EMAs (100-day or 200-day). The strategy also incorporates a time filter to ensure trades are executed only within specific time frames. This combination adds flexibility and adaptability to the strategy.

Advantages Analysis

The strength of this strategy lies in its simplicity and high adaptability. Multi-period EMAs provide a multi-dimensional view of market trends, increasing the accuracy of trading decisions. Additionally, the time filter avoids instability during specific market periods, reducing potential risks.

Risk Analysis

Despite its effectiveness, the strategy carries certain risks. The primary risk is market volatility due to unforeseen events, which may lead to strategy failure. Additionally, EMAs can be lagging, delaying the reflection of market changes. Methods to mitigate these risks include real-time market monitoring and combining other technical indicators to enhance decision accuracy.

Optimization Direction

Optimization directions for the strategy include the integrated use of various technical indicators, such as the Relative Strength Index (RSI) and Bollinger Bands, to deepen and broaden market analysis. Additionally, adjusting the periods of EMAs to better suit different market conditions could be beneficial.

Conclusion

Overall, this

multi-period EMA crossover quantitative trading strategy is an effective tool that can help traders make better decisions in a volatile market. With continuous optimization and adaptation to market changes, this strategy has the potential to achieve higher returns in future trading endeavors.

Parameters

NameDefaultWhat it controls
v_input_110Periodo_1
v_input_2100Periodo_2
v_input_3200Periodo_3
v_input_42000Desde año
v_input_int_1trueDesde mes
v_input_int_2trueDesde dia
v_input_52030Hasta año
v_input_int_3trueHasta mes
v_input_int_4trueHasta dia

Source Pine Script

/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
start = timestamp(2023,1,1,0,0)
end = timestamp(2024,1,1,0,0)
strategy("Tester Emas", overlay = true)

periodo1 = input(10,"Periodo_1")
periodo2 = input(100,"Periodo_2")
periodo3 = input(200,"Periodo_3")

//definir media moviles
ema1 = ta.ema(close,periodo1)
ema2 = ta.ema(close,periodo2)
ema3 = ta.ema(close,periodo3)

//Desde
desde_a = input(2000, title = "Desde año")
desde_m = input.int(   1, title = "Desde mes", minval=1, maxval = 12)
desde_d = input.int(   1, title = "Desde dia", minval=1, maxval = 31)

//Hasta
hasta_a = input(2030, title = "Hasta año")
hasta_m = input.int(   1, title = "Hasta mes", minval=1, maxval = 12)
hasta_d = input.int(   1, title = "Hasta dia", minval=1, maxval = 31)

FechaValida() => true

//Condicion de entradas
longCondition = ta.crossover(ema1, ema2)
shortCondition = ta.crossunder(ema1,ema2)

alcista = (ema1 > ema2) and (ema2 > ema3)
comprado =strategy.position_size > 0



//Comprar o vender segun las condiciones de entradas

//if (longCondition)
if (not comprado and alcista and FechaValida())
    // Round redondea mi capital para comprar las acciones en cantidades enteras
    cantidad = math.round(strategy.equity/ close)
    strategy.entry("Compra", strategy.long, cantidad)
//if (shortCondition)
if (comprado and not alcista and FechaValida())
    //strategy.entry("Venta", strategy.short)
    strategy.close("Compra" , comment = "Venta")

if (comprado and not FechaValida())
    //Cierre x finalizacion de periodo
    //strategy.entry("Venta", strategy.short)
    strategy.close("Compra" , comment = "Venta x fin")

//Graficar las medias moviles
plot(ema1, color = color.green, title = "Ema1")
plot(ema2, color = color.yellow, title = "Ema2")
plot(ema3, color = color.red, title = "Ema2")
//GMarca los cruces de medias
bgcolor(longCondition ? color.green : na)
bgcolor(shortCondition ? color.red : na)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-27. 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/Multi-Period-EMA-Crossover-Quantitative-Trading-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