estratégia de negociação a curto prazo

Autora:ChaoZhang, Data: 2023-10-25 14:40:21
Tags:

img

Resumo

Esta é uma estratégia de negociação de curto prazo baseada em breakouts de canal. Ele usa as breakouts do canal superior e inferior para determinar o início e o fim das tendências, e tomar decisões de negociação em conformidade.

Estratégia lógica

  1. A estratégia calcula, em primeiro lugar, a maior e a menor altitude durante um determinado período para construir o trilho superior e inferior do canal.

  2. Se o preço ultrapassar a linha superior, vá longo. Se o preço ultrapassar a linha inferior, vá curto.

  3. Usar um stop loss móvel para controlar os riscos.

  4. Existem duas regras de saída opcionais: voltar para a linha do meio ou seguir o stop loss em movimento.

  5. O período do canal e outros parâmetros podem ser ajustados para otimizar a estratégia para diferentes condições de mercado.

Análise das vantagens

  1. Simples de implementar, basta monitorizar a relação preço-canal e seguir as regras para negociar.

  2. Negociar ao longo da tendência, sem riscos de contra-tendência.

  3. Um canal claro e intuitivo dá sinais de entrada explícitos.

  4. Uma boa margem de lucro, pode alcançar retornos satisfatórios na maioria dos casos.

  5. Muitos parâmetros ajustáveis para otimização em diferentes mercados.

Análise de riscos

  1. A fuga pode falhar, existem riscos de ficarmos presos.

  2. O canal precisa de um período de formação, não adequado para mercados de gama limitada.

  3. A reversão para o stop loss médio pode ser demasiado conservadora, incapaz de manter as tendências.

  4. A otimização de parâmetros requer dados históricos, sobreajuste possível na negociação ao vivo.

  5. A negociação mecânica de pontos de ruptura pode aumentar a frequência de negociação e os custos de deslizamento.

Orientações de otimização

  1. Avalie os canais de diferentes períodos e selecione o mais adequado.

  2. Teste a reversão para o meio e a movimentação de stop loss para encontrar um melhor mecanismo de saída.

  3. Otimizar a percentagem de stop loss para reduzir as hipóteses de ser parado.

  4. Adicionar um filtro de tendência para evitar operações de ruptura inadequadas.

  5. Considere aumentar o tamanho da posição mas controlar os riscos.

Resumo

No geral, esta é uma estratégia de breakout madura de curto prazo. Tem regras de entrada claras, controle de risco adequado e funciona bem em geral. Uma melhoria adicional pode ser alcançada através do ajuste de parâmetros. Mas devem ser notadas limitações inerentes, ajustes necessários para diferentes mercados. Se usado sistematicamente, deve gerar lucros globais consistentes.


/*backtest
start: 2022-10-18 00:00:00
end: 2023-10-24 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/
// Strategy testing and optimisation for free Bitmex trading bot 
// © algotradingcc 

//@version=4
strategy("Channel Break [for free bot]", overlay=true, default_qty_type= strategy.percent_of_equity, initial_capital = 1000, default_qty_value = 20, commission_type=strategy.commission.percent, commission_value=0.075)

//Options
buyPeriod = input(13, "Channel Period for Long position")
sellPeriod = input(18, "Channel Period for Short position")
isMiddleExit = input(true, "Is exit on Base Line?")
takeProfit = input(46, "Take Profit (%) for position")
stopLoss = input(9, "Stop Loss (%) for position")

// Test Start
startYear = input(2005, "Test Start Year")
startMonth = input(1, "Test Start Month")
startDay = input(1, "Test Start Day")
startTest = timestamp(startYear,startMonth,startDay,0,0)

//Test End
endYear = input(2050, "Test End Year")
endMonth = input(12, "Test End Month")
endDay = input(30, "Test End Day")
endTest = timestamp(endYear,endMonth,endDay,23,59)

timeRange = time > startTest and time < endTest ? true : false

// Long&Short Levels
BuyEnter = highest(buyPeriod)
BuyExit = isMiddleExit ? (highest(buyPeriod) + lowest(buyPeriod)) / 2: lowest(buyPeriod)

SellEnter = lowest(sellPeriod)
SellExit = isMiddleExit ? (highest(sellPeriod) + lowest(sellPeriod)) / 2: highest(sellPeriod)

// Plot Data
plot(BuyEnter, style=plot.style_line, linewidth=2, color=color.blue, title="Buy Enter")
plot(BuyExit, style=plot.style_line, linewidth=1, color=color.blue, title="Buy Exit", transp=50)
plot(SellEnter, style=plot.style_line, linewidth=2, color=color.red, title="Sell Enter")
plot(SellExit, style=plot.style_line, linewidth=1, color=color.red, title="Sell Exit", transp=50)

// Calc Take Profits & Stop Loss
TP = 0.0
SL = 0.0
if strategy.position_size > 0
    TP := strategy.position_avg_price*(1 + takeProfit/100)
    SL := strategy.position_avg_price*(1 - stopLoss/100)

if strategy.position_size > 0 and SL > BuyExit
    BuyExit := SL
    
if strategy.position_size < 0
    TP := strategy.position_avg_price*(1 - takeProfit/100)
    SL := strategy.position_avg_price*(1 + stopLoss/100)

if strategy.position_size < 0 and SL < SellExit
    SellExit := SL
    
    
// Long Position    
if timeRange and strategy.position_size <= 0
    strategy.entry("Long", strategy.long, stop = BuyEnter)
strategy.exit("Long Exit", "Long", stop=BuyExit, limit = TP, when = strategy.position_size > 0)


// Short Position
if timeRange and strategy.position_size >= 0
    strategy.entry("Short", strategy.short, stop = SellEnter)
    
strategy.exit("Short Exit", "Short", stop=SellExit, limit = TP, when = strategy.position_size < 0)

// Close & Cancel when over End of the Test
if time > endTest
    strategy.close_all()
    strategy.cancel_all()


Mais.