Estratégia de inversão de impulso

Autora:ChaoZhang, Data: 2024-01-03 17:14:15
Tags:

img

Resumo

Esta estratégia é uma estratégia de reversão de momento baseada em médias móveis e no índice de força relativa (RSI).

Estratégia lógica

A estratégia usa uma média móvel de 14 dias como linha de sinal rápida e uma média móvel de 28 dias como linha lenta.

Quando o MA de 14 dias cruza acima do MA de 28 dias e o RSI está abaixo de 30 ou o RSI está abaixo de 13, ele sinaliza uma reversão no ímpeto para cima, provocando uma entrada longa.

Além disso, a estratégia tem um mecanismo de lucro parcial: quando o lucro da posição aberta atinge o nível de lucro definido (default 8%), ele irá obter lucro parcial (default 50%).

Análise das vantagens

A estratégia combina as vantagens das médias móveis, evitando perdas de fenda.

  1. Usando médias móveis rápidas e lentas filtra algum ruído.

  2. Os indicadores RSI mostram níveis de sobrecompra e sobrevenda, evitando a busca de novos máximos.

  3. O lucro parcial bloqueia alguns lucros e reduz o risco.

Análise de riscos

  1. A dupla média móvel pode produzir crossovers, levando a perdas.

  2. O nível de lucro pode ser ajustado para equilibrar risco versus recompensa.

Orientações de otimização

  1. Teste diferentes combinações de parâmetros de médias móveis para encontrar configurações ideais.

  2. Teste diferentes níveis de limiar do RSI.

  3. Ajustar o nível de lucro parcial e o rácio de venda para equilibrar o risco/recompensa.

Conclusão

Em geral, esta é uma estratégia típica de reversão média. Ele usa cruzes MA rápidas / lentas para determinar as voltas do mercado complementadas por RSI para filtrar sinais. Ele também implementa a tomada de lucro parcial para bloquear alguns lucros. A estratégia é simples, mas prática. Os parâmetros podem ser ajustados para atender a diferentes condições do mercado.


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

//@version=3
strategy(title = "14/28 SMA and RSI", shorttitle = "14/28 SMA and RSI", overlay = false, pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, currency = currency.USD)
src = close, len = input(14, minval=1, title="Length")
take_Profit=input(8, title="Take Profit")
quantityPercentage=input(50, title="Percent of Quantity to Sell")
closeOverbought=input(true, title="Close Overbought and Take Profit")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
longCondition = 0
sellCondition = 0
takeProfit = 0
quantityRemainder = 100
smaSignal = input(14, title="SMA Signal Period")
smaLong = input(28, title="SMA Longer Period")
if ((sma(close, smaSignal) >= sma(close, smaLong) and rsi<= 30) or (rsi<=13)) and strategy.position_size==0
    longCondition:=1

if longCondition==1
    strategy.entry("Buy", strategy.long)
    
profit = ((close-strategy.position_avg_price)/strategy.position_avg_price) * 100

if sma(close, smaSignal) <= sma(close, smaLong) and strategy.position_size>1
    sellCondition := 1

if strategy.position_size>=1
    if closeOverbought == true
        if profit>=take_Profit and takeProfit == 0
            strategy.exit("Take Profit", profit=take_Profit, qty_percent=quantityPercentage)
            takeProfit:=1
            quantityRemainder:=100-quantityPercentage
    if sellCondition == 1 and quantityRemainder<100
        strategy.close("Buy")

    if closeOverbought == false and rsi>70
        strategy.close("Take Profit")
        
plot(longCondition, "Buy Condition", green)
plot(takeProfit, "Partial Sell Condition", orange)
plot(sellCondition, "Sell Condition", red)

Mais.