
A estratégia de rastreamento de tendências de cruzamento de médias móveis é uma estratégia de negociação quantitativa para rastrear tendências de mercado. A estratégia gera sinais de negociação para capturar os pontos de inflexão de tendências de mercado, calculando médias móveis rápidas e médias móveis lentas e gerando sinais de negociação quando elas se cruzam.
O princípio central da estratégia é o uso de diferentes parâmetros de EMA para julgar a tendência do mercado. A estratégia define um EMA rápido e um EMA lento. Quando o EMA rápido atravessa o EMA lento de baixo para cima, o mercado vira-se bull; Quando o EMA rápido atravessa o EMA lento de cima para baixo, o mercado vira-se bear.
A estratégia abrirá uma carta em cima e uma carta em baixo. A estratégia manterá a posição até que o stop loss seja acionado ou um sinal de reversão de cruzamento ocorra novamente.
A estratégia tem as seguintes vantagens:
A estratégia também apresenta alguns riscos:
Para reduzir o risco, considere combinar outros indicadores para determinar o tipo de tendência, ou configure um Stop Loss Ratio mais flexível.
A estratégia também pode ser melhorada nos seguintes aspectos:
A estratégia de rastreamento de tendências de cruzamento de equilíbrio móvel é uma estratégia de negociação de tendências simples e prática. A ideia central da estratégia é clara e fácil de praticar, mas há também um certo espaço para otimização.
/*backtest
start: 2024-01-28 00:00:00
end: 2024-02-04 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy('Zhukov trade', overlay=true, calc_on_every_tick=true, currency=currency.USD)
// INPUT:
// Options to enter fast and slow Exponential Moving Average (EMA) values
emaFast = input.int(title='Fast EMA', defval=10, minval=1, maxval=9999)
emaSlow = input.int(title='Slow EMA', defval=20, minval=1, maxval=9999)
// Option to select trade directions
tradeDirection = input.string(title='Trade Direction', options=['Long', 'Short', 'Both'], defval='Both')
// Options that configure the backtest date range
startDate = input(title='Start Date', defval=timestamp('01 Jan 2023 00:00'))
endDate = input(title='End Date', defval=timestamp('31 Dec 2030 23:59'))
// Set take profit and stop loss percentages
take_profit_percent = input(1.0, title ="Take Profit Percent") / 100.0
stop_loss_percent = input(1.0, title ="Stop Loss Percent") / 100.0
// CALCULATIONS:
// Use the built-in function to calculate two EMA lines
fastEMA = ta.ema(close, emaFast)
slowEMA = ta.ema(close, emaSlow)
emapos = ta.ema(close, 200)
// PLOT:
// Draw the EMA lines on the chart
plot(series=fastEMA, color=color.new(color.orange, 0), linewidth=2)
plot(series=slowEMA, color=color.new(color.blue, 0), linewidth=2)
plot(series=emapos, color=color.new(color.red, 0), linewidth=2)
// CONDITIONS:
// Check if the close time of the current bar falls inside the date range
inDateRange = true
// Translate input into trading conditions
longOK = tradeDirection == 'Long' or tradeDirection == 'Both'
shortOK = tradeDirection == 'Short' or tradeDirection == 'Both'
// Decide if we should go long or short using the built-in functions
longCondition = ta.crossover(fastEMA, slowEMA) and inDateRange
shortCondition = ta.crossunder(fastEMA, slowEMA) and inDateRange
// ORDERS:
// Submit entry (or reverse) orders
if longCondition and longOK
strategy.entry(id='long', direction=strategy.long)
if shortCondition and shortOK
strategy.entry(id='short', direction=strategy.short)
// Exit orders
if strategy.position_size > 0 and longOK
strategy.exit(id='exit long', from_entry='long', limit=strategy.position_avg_price * (1 + take_profit_percent), stop=strategy.position_avg_price * (1 - stop_loss_percent))
if strategy.position_size < 0 and shortOK
strategy.exit(id='exit short', from_entry='short', limit=strategy.position_avg_price * (1 - take_profit_percent), stop=strategy.position_avg_price * (1 + stop_loss_percent))