
这是一个利用市场两方向强势突破信号进行双向开仓的策略。它会在出现同向两个强势K线后选择方向开仓,然后设置止盈止损,进行风险管理。
该策略基于两个强势K线信号判断市场方向。具体来说,它会计算每个K线的涨跌幅,当连续两个K线的涨跌幅都超过用户设定的门槛后(如6%),则判断该方向为强势方向,在第三根K线开仓做多/空。
做多条件:连续两根K线收盘价较上一日收盘价涨幅超过6% 做空条件:连续两根K线收盘价较上一日收盘价跌幅超过6%
开仓后会设定止盈止损距离来控制风险。止盈距离由用户输入,止损距离是开仓价格的一定倍数(如8倍)。
该策略还具有一些辅助功能来控制风险,如只在特定时间段开仓,设定最大亏损金额等。
这是一个较为稳定可靠的双向交易策略。主要优势有:
利用双向交易,可以在市场上升和下跌时都获得收益,增加稳定性。
基于两个强势信号判断趋势,可以有效过滤噪音,进入的仓位质量较高。
止盈止损设置合理,有利于风险控制,亏损有限。
辅助功能比较完善,如时间控制、最大亏损控制等,可以很好控制风险。
易于实盘验证和优化,策略逻辑简单清晰。
该策略主要风险有:
市场震荡时,容易出现 stopwords 损失。可以适当调整第一个信号判断参数,确保信号质量。
遇到三根超强势K线的概率较小,开仓机会可能较少。可以适当调低参数,但需要权衡信号质量。
突发事件带来的非理性行为可能导致超出止损距离的大幅亏损。这需要辅助的最大亏损额度控制来解决。
双向交易在具体实施时,要注意资金管理问题。如果资金分配不均可能导致账户只盈不亏。
该策略可以从以下几个方面进一步优化:
优化第一个信号的判断逻辑,提高信号质量。可以考虑加入更多因素,如交易量变化、波动率等。
优化止盈止损标准。可以根据不同市场调整参数,使盈亏比更合理。止损距离也可以设置为动态止损。
加入更多风险控制模块。例如最大单日亏损、最大连续亏损等。保证资金安全高效使用。
对资金使用比例进行优化。使多空交易资金分配更加合理,防止只赚不赔。
针对不同交易品种设定不同参数组合进行回测优化,提高适应性。
本策略是一个较为稳健的双向补仓策略。它信号质量较高,具有一定的风险控制能力。优化空间也较大,可进一步提升收益稳定性。该策略适合中长线趋势市,也可在震荡行情中夺取机会。
/*backtest
start: 2022-11-20 00:00:00
end: 2023-11-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="GAVAD", shorttitle="GAVAD", overlay=false, initial_capital=36000)
////////////////////////////////////////////////////////
// //
// //
// GAVAD % //
// //
// //
////////////////////////////////////////////////////////
Sinal = input(6, title="Sinal", type=input.integer, minval=1, maxval=150)
//Objetivo = input(6, title="Objetivo", type=input.integer, minval=1, maxval=100)
Multip = input(10000, title="Sinal", type=input.integer, minval=1, maxval=100000)
//GavadEntrada1 = (close - low [1])/close[1]
//plot(GavadEntrada1, style=plot.style_line, linewidth=3, color=color.yellow)
//sombra
//DownOL = (low - open ) / open * -10000
//plot(DownOL, style=plot.style_area, linewidth=3, color=color.silver)
// imprime o GAVAD
GavadEntrada = (close - close [1])/close[1] * Multip
plot(GavadEntrada, style=plot.style_histogram, linewidth=3, color=color.purple)
//linha do Sinal
plot(Sinal, style=plot.style_line, linewidth=1, color=color.yellow)
//linha do Objetivo
//plot(Objetivo, style=plot.style_line, linewidth=1, color=color.white)
Fura1 = GavadEntrada [0] >= Sinal
Fura2 = GavadEntrada [1] >= Sinal
Alert = Fura1
plotshape(Alert, style=shape.circle, location = location.top, color= color.yellow)
SinalON = Fura1 and Fura2
plotshape(SinalON, style=shape.circle, location = location.bottom, color= color.green)
////////////////////////////////////////////////////////
// //
// //
// CONDIÇÕES DE OPERACAO //
// //
// //
////////////////////////////////////////////////////////
Sell_Forte2 = SinalON
//plotshape(Sell_Forte2, style=shape.xcross, color=color.yellow, location=location.bottom)
//Call_Forte2 = SinalON
//plotshape(Call_Forte2, style=shape.xcross, color=color.yellow, location=location.top)
////////////////////////////////////////////////////////
// //
// //
// CALENDARIO //
// //
// //
////////////////////////////////////////////////////////
//052)
// trading view solicita que se ja informado data para gerar backtest a partir de tal data
//começa backtest do trading sistem em qual data ?
ano = input(2021, minval=1, title="Ano")
mes = input(1, minval=1, maxval=12, title="Mes")
dia = input(1, minval=1, maxval=30, title="Dia")
hora = input(0, minval=1, maxval=23, title="hora")
minuto = input(0, minval=1, maxval=59, title="minuto")
horaabertura = input(10, minval=1, maxval=23, title="hora Inicio Operacao Robo")
minutoabertura = input(40, minval=1, maxval=59, title="Minuto Encerra Tudo")
horaencerra = input(17, minval=1, maxval=23, title="hora Fechamento")
minutoencerra = input(50, minval=1, maxval=59, title="Minuto Encerra Novas Operacoes")
minutofinaliza = input(50, minval=1, maxval=59, title="Minuto Encerra Tudo")
//valida se o dia de hoje é posterior ao dia informado acima
Validadia = year >= ano and month >= mes and dayofmonth >= dia
//cria horario de abertura de negociaçao, considerar default 10 hs, pois os indicadores ja estarão corrigidos
abreloja = year >= ano and month >= mes and dayofmonth >= dia and hour >= horaabertura
//and minute >= minutoabertura)
//cria horario de fechamento de todas as negociaçoes, considerar default 17:00 hs
//nenhuma ordem pode ser aberta depois dessa data e as abertas devem ser fechadas
fechaloja = year >= ano and month >= mes and dayofmonth >= dia and hour >= horaencerra
//and minute >= minutoencerra)
fechaloja2 = year >= ano and month >= mes and dayofmonth >= dia and hour >= horaencerra
//and minute >= minutofinaliza)
//valida horario de negociação, pra liberar as operacoes.
lojaaberta = abreloja == true and fechaloja == false and fechaloja2 == false
////////////////////////////////////////////////////////
// //
// //
// GERENCIAMENTO DE RISCO //
// //
// //
////////////////////////////////////////////////////////
//seta meta mensal
meta = input(150000, "Meta de Lucro")
Contratos= input(5, "Contratos")
//seta tamanho do lote (ordem inicial-unica)
tamanhodolote = Contratos
//seta stop gain final em pontos (metade da barra anterior)
//gaintotal = input(30, "Gain")
gaintotal = input(3, "Gain")
//seta stop loss final em pontos
lossmaximo = input(8, "Loss")
//lossmaximo = (open- close)*100
////////////////////////////////////////////////////////
// //
// Checkbox //
// //
////////////////////////////////////////////////////////
//ativacomprasretorno = input(title="Ativar Compras Retorno", type=input.bool , defval=true)
//ativavendasretorno = input(title="Ativar Vendas Retorno", type=input.bool , defval=true)
////////////////////////////////////////////////////////
// //
// //
// COMPRA E VENDA //
// //
// //
////////////////////////////////////////////////////////
Tradenumber = strategy.closedtrades + 1
Batemeta = strategy.netprofit < meta
//COMPRA RETORNO
//longcondition2 = Validadia and Call_Forte2 and Batemeta
//strategy.entry("Comprar", strategy.long, tamanhodolote, when=longcondition2, comment="[Oper=" + tostring(Tradenumber) + "]win=" + tostring(strategy.wintrades) + " | Loss=" + tostring(strategy.losstrades))
//strategy.exit("Saida Compra", "Comprar", profit=gaintotal, loss=lossmaximo)
//if (CruzamentoFechaCallGG)
//strategy.close(id="Comprar")
//if (EscapeFechaCall)
// strategy.close(id="Comprar")
//plotchar(longcondition2, char="C", location=location.bottom, color=color.lime, transp=0)
//alertcondition(longcondition2, "Comprar", "Compra Rápida!")
//VENDA RETORNO
Shortcondition2 = Validadia and Sell_Forte2 and Batemeta
strategy.entry("Vender", strategy.short, tamanhodolote, when=Shortcondition2)
strategy.exit("Fecha Venda", "Vender", profit=gaintotal, loss=lossmaximo)
//if (CruzamentoFechaSellGG)
// strategy.close(id="Vender")
//if (EscapeFechaSell)
// strategy.close(id="Comprar")
//plotchar(CruzamentoFechaSellGG, char="Y", location=location.top, color=color.lime, transp=0)
//plotchar(longcondition2, char="S", location=location.bottom, color=color.lime, transp=0)
//alertcondition(longcondition2, "Vender", "Venda Rápida!")
//fim do codigo