Tendência de seguir uma estratégia baseada na média móvel

Autora:ChaoZhang, Data: 2024-01-22 17:26:04
Tags:

img

Resumo

Estratégia lógica

Análise das vantagens

As vantagens desta estratégia incluem:

  1. Utiliza médias móveis como base para filtrar o ruído do mercado a curto prazo e seguir as tendências.
  2. Lógica simples e clara, fácil de entender e implementar, adequada para iniciantes.

Análise de riscos

Existem também alguns riscos:

  1. São propensos a sinais falsos quando os preços se movem para o lado.

Orientações de otimização

Algumas orientações de otimização:

  1. Adicione estratégias de stop loss para limitar a queda em negociações individuais.

Conclusão

Esta estratégia constrói um sistema de negociação baseado em duplos crossovers EMA, usando relações EMA rápidas e lentas para determinar a tendência do mercado. A geração de sinal é simples e clara. Filtra algum ruído e acompanha as tendências, adequado para negociação de tendências de médio a longo prazo. Há espaço para melhorar a universalidade e a eficiência através da otimização de múltiplos indicadores e controle de risco.


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

//@version=2
strategy("EMA Strategy v2", shorttitle = "EMA Strategy v2", overlay=true, pyramiding = 3,default_qty_type = strategy.percent_of_equity, default_qty_value = 10)


// === Inputs ===
// short ma
maFastSource   = input(defval = close, title = "Fast MA Source")
maFastLength   = input(defval = 30, title = "Fast MA Period", minval = 1)

// long ma
maSlowSource   = input(defval = close, title = "Slow MA Source")
maSlowLength   = input(defval = 100, title = "Slow MA Period", minval = 1)

// invert trade direction
tradeInvert = input(defval = false, title = "Invert Trade Direction?")
// risk management
useStop     = input(defval = true, title = "Use Initial Stop Loss?")
slPoints    = input(defval = 0, title = "Initial Stop Loss Points", minval = 1)
useTS       = input(defval = true, title = "Use Trailing Stop?")
tslPoints   = input(defval = 0, title = "Trail Points", minval = 1)
useTSO      = input(defval = false, title = "Use Offset For Trailing Stop?")
tslOffset   = input(defval = 0, title = "Trail Offset Points", minval = 1)

// === Vars and Series ===
fastMA = ema(maFastSource, maFastLength)
slowMA = ema(maSlowSource, maSlowLength)

plot(fastMA, color=blue)
plot(slowMA, color=purple)

goLong() => crossover(fastMA, slowMA)
killLong() => crossunder(fastMA, slowMA)
strategy.entry("Buy", strategy.long, when = goLong())
strategy.close("Buy", when = killLong())

// Shorting if using
goShort() => crossunder (fastMA, slowMA)
killShort() => crossover(fastMA, slowMA)
//strategy.entry("Sell", strategy.short, when = goShort())
//strategy.close("Sell", when = killShort())

if (useStop)
    strategy.exit("XLS", from_entry ="Buy", stop = strategy.position_avg_price / 1.08 )
    strategy.exit("XSS", from_entry ="Sell", stop = strategy.position_avg_price * 1.58)

Mais.