Estratégia de reversão de perdas de rastreamento de tendências SAR parabólica

Autora:ChaoZhang, Data: 2024-02-01 14:54:09
Tags:

img

Resumo

A Estratégia de Reversão de Stop Loss para rastreamento de tendências parabólicas é uma estratégia que usa o indicador para identificar tendências e entrar em posições de contra-tendência quando a tendência se inverte.

Estratégia lógica

A estratégia usa o indicador Parabolic SAR para julgar a tendência atual do mercado. Parabolic SAR significa Parabolic Stop and Reverse. Suas linhas de indicador formam uma série de parábolas no gráfico de preços, e esses pontos de parábola representam pontos de reversão potenciais.

Quando os pontos SAR estão caindo e abaixo do preço, representa uma tendência de alta; quando os pontos SAR estão subindo e acima do preço, representa uma tendência de baixa.

Especificamente, quando os pontos SAR mostram uma tendência de alta e estão acima dos preços, a estratégia será curta; quando os pontos SAR mostram uma tendência de queda e estão abaixo dos preços, a estratégia será longa.

Além disso, a estratégia também define mecanismos de stop loss e take profit. Quando se vai long, pode definir um preço de stop loss para limitar as perdas; ao mesmo tempo, pode definir um preço de take profit para fechar posições após atingir um certo lucro alvo.

Análise das vantagens

As principais vantagens da combinação do indicador de tendência e dos mecanismos de stop loss/take profit são:

  1. Capturar oportunamente as oportunidades de tendência reversa para negociação de contra-tendência.
  2. Controlar ativamente os riscos e os lucros definindo o stop loss e o take profit.
  3. O SAR parabólico é um indicador inverso amplamente utilizado e eficaz.
  4. Regras de estratégia simples e claras, fáceis de compreender e implementar.

Análise de riscos

Há também alguns riscos a ter em conta para a estratégia:

  1. O indicador SAR parabólico não é perfeito, às vezes gera sinais errados.
  2. Os preços de stop loss e take profit devem ser estabelecidos de forma razoável, caso contrário, podem parar ou obter lucro prematuramente.
  3. As comissões de negociação também afetam os lucros totais.
  4. A nova tendência após a reversão pode ser de curta duração.

Estes riscos podem ser resolvidos através da otimização de parâmetros, da utilização de outros indicadores de filtro, etc.

Orientações de otimização

A estratégia pode ser otimizada nos seguintes aspectos:

  1. Otimizar os parâmetros SAR parabólicos para encontrar a melhor combinação.
  2. Tente diferentes estratégias de stop loss e aproveite estratégias de lucro como trailing stop loss.
  3. Adicionar indicadores ou condições para filtrar os sinais de negociação reversa.
  4. Adicionar controlo de posição baseado nas condições de mercado.
  5. Ajustar parâmetros para diferentes instrumentos de negociação.

Conclusão

Em geral, esta é uma estratégia de reversão de stop loss de rastreamento de tendência bastante clássica. Identifica reversões de tendência e também controla riscos com meios de stop loss e take profit. Após otimizações, pode se tornar uma estratégia valiosa para negociação ao vivo.


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

//@version=4
strategy("Parabolic SAR Strategy", overlay=true)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2)
var bool uptrend = na
var float EP = na
var float SAR = na
var float AF = start
var float nextBarSAR = na
if bar_index > 0
	firstTrendBar = false
	SAR := nextBarSAR
	if bar_index == 1
		float prevSAR = na
		float prevEP = na
		lowPrev = low[1]
		highPrev = high[1]
		closeCur = close
		closePrev = close[1]
		if closeCur > closePrev
			uptrend := true
			EP := high
			prevSAR := lowPrev
			prevEP := high
		else
			uptrend := false
			EP := low
			prevSAR := highPrev
			prevEP := low
		firstTrendBar := true
		SAR := prevSAR + start * (prevEP - prevSAR)
	if uptrend
		if SAR > low
			firstTrendBar := true
			uptrend := false
			SAR := max(EP, high)
			EP := low
			AF := start
	else
		if SAR < high
			firstTrendBar := true
			uptrend := true
			SAR := min(EP, low)
			EP := high
			AF := start
	if not firstTrendBar
		if uptrend
			if high > EP
				EP := high
				AF := min(AF + increment, maximum)
		else
			if low < EP
				EP := low
				AF := min(AF + increment, maximum)
	if uptrend
		SAR := min(SAR, low[1])
		if bar_index > 1
			SAR := min(SAR, low[2])
	else
		SAR := max(SAR, high[1])
		if bar_index > 1
			SAR := max(SAR, high[2])
	nextBarSAR := SAR + AF * (EP - SAR)
	if barstate.isconfirmed
		if uptrend
			strategy.entry("ParSE", strategy.short, stop=nextBarSAR, comment="ParSE")
			strategy.cancel("ParLE")
		else
			strategy.entry("ParLE", strategy.long, stop=nextBarSAR, comment="ParLE")
			strategy.cancel("ParSE")
plot(SAR, style=plot.style_cross, linewidth=3, color=color.orange)
plot(nextBarSAR, style=plot.style_cross, linewidth=3, color=color.aqua)
//Stop Loss Inputs
use_short_stop_loss = input(false, title="Short Stop Loss", group="Stop Loss and Take Profit", inline="Short_SL")
short_stop_loss = input(title="(%)", type=input.float, minval=0.0, step=0.1, 
     defval=5, group="Stop Loss and Take Profit", inline="Short_SL") * 0.01
use_long_stop_loss = input(false, title="Long Stop Loss", group="Stop Loss and Take Profit", inline="Long_SL")
long_stop_loss = input(title="(%)", type=input.float, minval=0.0, step=0.1, 
     defval=5, group="Stop Loss and Take Profit", inline="Long_SL") * 0.01

//Take Profit Inputs     
use_short_take_profit = input(false, title="Short Take Profit", group="Stop Loss and Take Profit", inline="Short_TP")
short_take_profit = input(title="(%)", type=input.float, minval=0.0, step=0.1,
     defval = 20, group="Stop Loss and Take Profit", inline="Short_TP") * .01
use_long_take_profit = input(false, title="Long Take Profit", group="Stop Loss and Take Profit", inline="Long_TP")
long_take_profit = input(title="(%)", type=input.float, minval=0.0, step=0.1,
     defval = 20, group="Stop Loss and Take Profit", inline="Long_TP") * .01


longStopPrice  = strategy.position_avg_price * (1 - long_stop_loss)
shortStopPrice = strategy.position_avg_price * (1 + short_stop_loss)
longLimitPrice = strategy.position_avg_price * (1 + long_take_profit)
shortLimitPrice = strategy.position_avg_price * (1 - short_take_profit)


if (strategy.position_size > 0.0)
    if (use_long_stop_loss and not use_long_take_profit)
        strategy.exit("Long", stop = longStopPrice)
    if (use_long_take_profit and not use_long_stop_loss)
        strategy.exit("Long", limit = longLimitPrice)
    if (use_long_take_profit and use_long_stop_loss)
        strategy.exit("Long", stop = longStopPrice, limit=longLimitPrice)
if (strategy.position_size < 0.0)
    if (use_short_stop_loss and not use_short_take_profit)
        strategy.exit("Short", stop = shortStopPrice)
    if (use_short_take_profit and not use_short_stop_loss)
        strategy.exit("Short", limit = shortLimitPrice)
    if (use_short_take_profit and use_short_stop_loss)
        strategy.exit("Short", stop = shortStopPrice, limit = shortLimitPrice)

//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

Mais.