Estratégia de recuperação de impulso

Autora:ChaoZhang, Data: 2023-12-12 16:34:52
Tags:

img

Resumo

A estratégia de pullback de momento identifica leituras extremas do RSI como sinais de momento para uma estratégia longa / curta.

O mercado de ações de curto/longo prazo entra em curto/longo prazo no primeiro pullback para a EMA de 5 períodos (baixo) / 5 períodos (alto) e sai na alta/baixo de 12 bares.

A taxa de stop loss sugerida é de X ATRs (ajustáveis em entradas) a partir do preço de entrada.

A estratégia é bastante robusta em todos os prazos e mercados, com uma taxa de ganho de 60% a 70% e negociações vencedoras maiores.

Estratégia lógica

  1. Calcular o RSI de 6 períodos e identificar valores superiores a 90 (supercomprado) e inferiores a 10 (supervendido).

  2. Quando o RSI estiver sobrecomprado, vá longo em um pullback para a EMA de 5 períodos (baixo) dentro de 6 bares.

  3. Quando o RSI estiver sobrevendido, vá curto em um pullback para a EMA de 5 períodos (maior) dentro de 6 bares.

  4. A estratégia de saída é uma saída de lucro móvel, com o objetivo inicial sendo a maior alta/menor baixa dos últimos 12 bares, atualizando em cada nova barra para uma saída rolante.

  5. A taxa de stop loss é de X ATRs a partir do preço de entrada (personalizável).

Análise das vantagens

A estratégia combina os extremos do RSI como sinais de impulso e entradas de retração para capturar pontos de reversão potenciais nas tendências, com uma alta taxa de vitória.

O mecanismo de transferência de lucros bloqueia lucros parciais de acordo com a ação real dos preços, reduzindo os drawdowns.

A parada ATR ajuda a controlar eficazmente a perda de uma única transacção.

Boa robustez para aplicação em diferentes mercados e conjuntos de parâmetros para uma fácil replicação da negociação real.

Análise de riscos

Um stop loss muito amplo se o multiplicador ATR for muito elevado, aumentando a perda por transação.

A mudança do mecanismo de captação de lucros pode reduzir a margem de lucro se ocorrer uma consolidação prolongada.

Transações perdidas se o pullback ultrapassar 6 bares.

Possível deslizamento ou falha se ocorrerem grandes eventos noticiosos.

Orientações de otimização

Teste de redução do número de barras de entrada de 6 para 4 para melhorar a taxa de entrada.

Teste aumentando o multiplicador ATR para aumentar a perda de controlo por transacção.

Incorporar indicadores de volume para evitar perdas decorrentes de divergências na consolidação.

Introduzir no intervalo de retirada de 60 minutos no ponto médio para filtrar o ruído.

Conclusão

A Momentum Pullback Strategy é uma abordagem geral muito prática de reversão média de curto prazo, incorporando elementos de tendência, reversão e gerenciamento de risco para facilitar a negociação real, mantendo ainda o potencial de geração de alfa.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Marcns_

//@version=5
strategy("M0PB", commission_value = 0.0004, slippage = 1, initial_capital=30000)
// commision is equal to approx $3.8 per round trip which is accurate for ES1! futures and slippage per trade is conservatively 1 tick in and 1 tick out. 

// *momentum pull back* //

// long / short strategy that identifies extreme readings on the rsi as a *momentum signal*
//Strategy buys/ sells a pullback to the 5ema(low)/ 5ema(high) and exits at rolling 12 bar high/ low. The rolling high/ low feature means that 
//if price enters into a pronlonged consolidation the profit target will begin to reduce with each new bar. The best trades tend to work within 2-6 bars
// hard stop is X atr's from postion average price. This can be adjusted in user inputs.
// built for use on 5 min & 1min intervals on: FX, Indexes, Crypto
// there is a lot of slack left in entries and exits but the overall strategy is fairly robust across timeframes and markets and has between 60%-70% winrate with larger winners.
// signals that occur from economic news volatility are best avoided.  


// define rsi
r = ta.rsi(close,6) 

// find rsi > 90
b = 0.0

if r >= 90
    b := 1.0
else
    na

// find rsi < 10
s = 0.0

if r <= 10
    s := -1.0
else
    na

// plot rsi extreme as painted background color
bgcolor(b ? color.rgb(255, 82, 82, 49): na)
bgcolor(s? color.rgb(76, 175, 79, 51): na)



// exponential moving averages for entries. note that source is high and low (normally close is def input) this creates entry bands
//entry short price using high as a source ta.ema(high,5)
es = ta.ema(high,5)

//entry long price using low as a source ta.ema(low,5)
el = ta.ema(low,5)


// long pullback entry trigger: last period above ema and current low below target ema entry 
let = 0.0

if low[1] > el[1] and low <= el
    let := 1.0
else
    na
//short entry trigger ""
set = 0.0

if high[1] < es[1] and high >= es
    set := -1.0
else
    na

// create signal "trade_l" if RSI > 90 and price pulls back to 5ema(low) within 6 bars
trade_l = 0.0

if ta.barssince(b == 1.0) < 6 and let == 1.0
    trade_l := 1.0
else
    na

plot(trade_l, "l_entry", color.green)

//create short signal "trade_s" if rsi < 10 and prices pullback to 5em(high) wihthin 6 bars
trade_s = 0.0

if ta.barssince(s == -1.0) < 6 and set == -1.0
    trade_s := -1.0
else
    na

plot(trade_s, "s_entry", color.purple)

// define price at time of trade_l signal and input value into trade_p to use for stop parems later
trade_p = strategy.position_avg_price

//indentify previous 12 bar high as part of long exit strat
// this creates a rolling 12 bar high target... a quick move back up will exit at previous swing high but if a consolidation occurs system will exit on a new 12 bar high which may be below prev local high
ph = ta.highest(12)

// inverse of above for short exit strat - previous lowest low of 12 bars as exit (rolling)
pl = ta.lowest(12)


// 1.5 atr stop below entry price (trade_p defined earlier) as part of exit strat
atr_inp = input.float(2.75, "atr stop", minval = 0.1, maxval = 6.0)

atr = ta.atr(10)

stop_l = trade_p - (atr* atr_inp)
stop_s = trade_p + (atr* atr_inp)

//strat entry long

strategy.entry("EL", strategy.long, 2, when = trade_l == 1.0)

//strat entry short

strategy.entry("ES", strategy.short, 2, when = trade_s == -1.0)   
    
//strat long exit

if strategy.position_size == 2
    strategy.exit(id = "ph", from_entry = "EL", qty = 2, limit = ph)
    if strategy.position_size == 2
        strategy.close_all(when = low[1] > stop_l[1] and low <= stop_l)

// strat short exit

if strategy.position_size == -2
    strategy.exit(id = "pl", from_entry = "ES", qty = 2, limit =pl)
    if strategy.position_size == -2
        strategy.close_all(when = high[1] < stop_s[1] and high >= stop_s)




// code below to trail remaining 50% of position //

 //if strategy.position_size == 1 
        //strategy.exit(id ="trail", from_entry = "EL", qty = 1, stop = el)
        


Mais.