Estratégia inteligente de suspensão de perdas

Autora:ChaoZhang, Data: 2024-01-25 12:50:12
Tags:

img

Resumo

Princípio da estratégia

A lógica central desta estratégia é ajustar automaticamente a linha de stop loss com base no indicador SAR. Especificamente, define quatro variáveis:

  • PE: Ponto extremo
  • SAR: Ponto de paragem de perdas corrente
  • AF: Fator de passo, utilizado para controlar a magnitude de ajuste da linha de perda de parada

A magnitude de ajuste da linha de stop loss é controlada pelo Step Factor AF. AF aumentará quando um novo ponto de stop loss for definido com sucesso, expandindo assim a próxima magnitude de ajuste.

Vantagens

Especificamente, existem as principais vantagens:

  1. Reduzir o máximo de retirada: ajuste inteligente da linha de stop loss pode sair antes da inversão da tendência para maximizar a proteção do lucro realizado
  2. Capture Trends: A linha de stop loss irá ajustar com novos máximos ou mínimos e automaticamente seguir as tendências de preços
  3. Parâmetros personalizáveis: Os utilizadores podem personalizar o valor do passo AF e o valor inicial com base nas suas próprias preferências de risco para controlar a sensibilidade dos ajustes de stop loss

Análise de riscos

Há também alguns riscos a considerar para esta estratégia:

  1. Excessiva sensibilidade: se o ajuste da fase AF for demasiado grande ou o valor inicial for demasiado pequeno, a linha de stop loss será demasiado sensível e pode ser desencadeada pelo ruído do mercado a curto prazo
  2. Perda de oportunidades: Ativar o stop loss demasiado cedo pode também resultar em perder oportunidades lucrativas da continuação da alta
  3. Seleção de parâmetros: configurações de parâmetros inadequadas também afetarão o desempenho da estratégia e as necessidades de ajustamento para diferentes mercados

Orientações de otimização

A estratégia pode também ser otimizada nos seguintes aspectos:

  1. Combinar com outros indicadores: Ajuste da linha de stop loss em pausa quando os principais indicadores do ciclo emitirem sinais para evitar o stop loss prematuro antes da inversão da tendência
  2. Adicionar módulo de auto-adaptação de parâmetros: otimize automaticamente parâmetros com base em dados históricos usando algoritmos de aprendizado de máquina
  3. Stop Loss de vários níveis: Configure várias linhas de stop loss para acompanhar diferentes magnitudes de flutuações do mercado

Conclusão

A estratégia de stop loss inteligente ajusta as posições da linha de stop loss em tempo real, simulando a lógica operacional do indicador SAR. Ao mesmo tempo em que protege os lucros, também minimiza a possibilidade de oportunidades perdidas tanto quanto possível.

Em comparação com as estratégias de stop loss fixas tradicionais, esta estratégia pode adaptar-se melhor às mudanças do mercado e é mais flexível.

Naturalmente, há também certos espaços de otimização de parâmetros para esta estratégia, e efeitos melhorados que podem ser alcançados pela combinação de outros indicadores.


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

//@version=4
strategy("Lucid SAR Strategy", shorttitle="Lucid SAR Strategy", overlay=true)

// Full credit to Sawcruhteez, Lucid Investment Strategies LLC and Casey Bowman.
// This is a strategy version of the Lucid SAR indicator created by the above-mentioned parties.
// Original version of the indicator: https://www.tradingview.com/script/OkACQQgL-Lucid-SAR/

// Branded under the name "Lucid SAR" 
// As agreed to with Lucid Investment Strategies LLC on July 9, 2019
// https://lucidinvestmentstrategies.com/


// Created by Casey Bowman on July 4, 2019

// MIT License

// Copyright (c) 2019 Casey Bowman

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.


AF_initial = input(0.02)
AF_increment = input(0.02)
AF_maximum = input(0.2)


// start with uptrend
uptrend = true
newtrend = false
EP = high
SAR = low
AF = AF_initial

if not na(uptrend[1]) and not na(newtrend[1])
    if uptrend[1]
        EP := max(high, EP[1])
    else
        EP := min(low, EP[1])
    if newtrend[1]
        AF := AF_initial
    else
        if EP != EP[1]
            AF := min(AF_maximum, AF[1] + AF_increment)
        else
            AF := AF[1]
    SAR := SAR[1] + AF * (EP - SAR[1])
    if uptrend[1]
        if newtrend
            SAR := max(high, EP[1])
            EP := min(low, low[1])
        else
            SAR := min(SAR, low[1])
            if not na(low[2])
                SAR := min(SAR, low[2])
            if SAR > low
                uptrend := false
                newtrend := true
                SAR := max(high, EP[1])
                EP := min(low, low[1])
            else
                uptrend := true
                newtrend := false
    else
        if newtrend
            SAR := min(low, EP[1])
            EP := max(high, high[1])
        else
            SAR := max(SAR, high[1])
            if not na(high[2])
                SAR := max(SAR, high[2])
            if SAR < high
                uptrend := true
                newtrend := true
                SAR := min(low, EP[1])
                EP := max(high, high[1])
            else
                uptrend := false
                newtrend := false
            
        

plot(SAR, color = color.blue, style = plot.style_cross, linewidth = 2)

if (uptrend)
    strategy.entry("PBSARLE", strategy.long, comment="PBSARLE")
if (newtrend)
    strategy.entry("PBSARSE", strategy.short, comment="PBSARSE")

Mais.