
A estratégia de reversão de stop loss de acompanhamento de tendências é uma estratégia que usa o indicador Parabolic SAR para identificar tendências e entrar em posições de reversão quando as tendências se revertem. A estratégia combina mecanismos de stop loss e stop loss para controlar o risco.
A estratégia usa o indicador Parabolic SAR para julgar a tendência atual do mercado. O nome completo do Parabolic SAR é Parabolic Stop and Reverse, que significa que a linha de parada de perda de paralisação se inverte. Sua linha de indicador se assemelha a uma série de linhas de paralisação no gráfico de preços, onde os pontos de paralisação representam possíveis pontos de reversão.
Quando o SAR desce e está abaixo do preço, representa uma tendência de alta; quando o SAR sobe e está acima do preço, representa uma tendência de baixa. A estratégia é julgar a direção da tendência atual com base na posição do SAR.
Especificamente, quando o SAR está em alta tendência e acima do preço, a estratégia é fechada; quando o SAR está em baixa tendência e abaixo do preço, a estratégia é feita em uma posição mais. Ou seja, quando o SAR mostra uma reversão de tendência, entra em uma posição de reversão.
Além disso, a estratégia também estabelece mecanismos de stop loss e de stop-loss. Quando feito em excesso, é possível definir um preço de stop loss para limitar os prejuízos; ao mesmo tempo, é possível definir um preço de stop-loss para liquidar a posição depois que o preço atinge um determinado objetivo de lucro. O mercado livre também é um mecanismo semelhante.
A estratégia, combinada com indicadores de tendência e mecanismos de stop loss/stop loss, tem as seguintes principais vantagens:
A estratégia também apresenta alguns riscos que devem ser lembrados:
Os riscos podem ser resolvidos através da optimização de parâmetros de ajuste ou de filtragem de outros indicadores.
A estratégia pode ser otimizada em várias direções:
A estratégia de reversão de parada de perda de seguimento de tendência é, em geral, uma estratégia de negociação mais clássica. Ela desempenha a função de identificar a reversão de tendência, além de auxiliar o controle de risco com paradas e paradas. Com otimização, pode ser uma estratégia que vale a pena investir.
/*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)