停顿回转策略


创建日期: 2023-11-03 17:26:53 最后修改: 2023-11-03 17:26:53
复制: 0 点击次数: 451
avatar of ChaoZhang ChaoZhang
1
关注
1263
关注者

停顿回转策略

概述

该策略的主要思想是在股票价格出现明显的短期停顿之后,再根据“停顿”阶段形成的盘整态势判断价格可能的下一步走向,从而采取相应的做多做空操作。

策略原理

  1. 策略使用Stochastic oscillator指标判断股价是否进入了盘整,Stochastic oscillator在超买或超卖区域震荡时,表示股价进入盘整。

  2. 在Stochastic oscillator指标震荡时,根据K线实体方向来判断趋势转折点。当K线从阴转阳时判断为盘整结束,做多;当K线从阳转阴时判断为盘整结束,做空。

  3. 做多做空后的止盈止损根据入场点来设置,采用移动止盈止损。

  4. 该策略同时支持全仓操作和分仓操作。全仓时设置固定止盈止损点;分仓时设置移动止盈止损点。

  5. 该策略还设置了每天交易时间,只在设置的时间段内交易。

优势分析

  1. 利用Stochastic oscillator指标判断股价震荡状态,可准确判断出股价的短期盘整。

  2. 在震荡后的K线转折点进行操作,可提高操作准确性。

  3. 采用移动止盈止损,可根据股价行情进行止损点 trailing,可锁定更多获利。

  4. 支持全仓和分仓操作,可根据自己的风险偏好选择合适的操作方式。

  5. 设置了交易时间,可避免在股价异常波动时段进行错误操作。

风险分析

  1. Stochastic oscillator指标发出假信号的概率较大,可能错过买点卖点或者乱入。

  2. K线转折点判断不准确,可能在非转折点进行操作。

  3. 移动止损点随股价波动,可能被突破止损。

  4. 分仓操作风险较大,股价反转可能造成Loss扩大。

  5. 需要调整止损点和移动幅度,以适应不同股票的特点。

  6. 需要规避重大事件带来的股价异常波动对策略的影响。

优化方向

  1. 优化Stochastic oscillator的参数,使其更准确地识别出盘整区间。

  2. 结合其他指标确认K线转折信号,提高操作准确性。

  3. 优化移动止损算法,使止损点能更好跟踪股价。

  4. 添加仓位控制,避免单只股票输得太多。

  5. 结合重大事件发布时间,避开股价异常波动时段。

  6. 优化分仓模式,追踪更大的行情趋势。

总结

停顿回转策略利用Stochastic oscillator指标识别短线盘整,在震荡后的价格转折点进行操作。该策略具有较高的胜率,可锁定趋势中的获利。但Stochastic oscillator存在发出假信号的可能,操作准确性有待进一步提高。通过优化指标参数,添加过滤条件等方式可降低错误信号率。此外,优化止损算法和仓位控制,并规避重大事件影响,也是该策略需要重点优化的方向。总体来说,停顿回转策略具有一定的参考价值,但实盘中需要根据自己的交易方式进行适当调整和优化,以控制风险。

策略源码
/*backtest
start: 2022-10-27 00:00:00
end: 2023-11-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy('Cross', overlay=true, initial_capital=1000 )

// Creditos : Cleber.martinelli
////////////////////////////////////////////////////////
//                                                    //
//                                                    //
//                    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.int(2022, minval=1, title="Ano")
mes = input.int(1, minval=1, maxval=12, title="Mes")
dia = input.int(1, minval=1, maxval=31, title="Dia")
hora = input.int(1, minval=1, maxval=23, title="hora")
minuto = input.int(0, minval=0, maxval=59, title="minuto")
horaabertura = input.int(10, minval=1, maxval=23, title="hora Inicio Operacao Robo")
minutoabertura = input.int(40, minval=1, maxval=59, title="Minuto Encerra Tudo")
horaencerra = input.int(17, minval=1, maxval=23, title="hora Fechamento")
minutoencerra = input.int(50, minval=1, maxval=59, title="Minuto Encerra Novas Operacoes")
minutofinaliza = input.int(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

////////////////////////////////////////////////////////
//                                                    //
//                                                    //
//                 Codigo Operacional                 //
//                                                    //
//                                                    //
////////////////////////////////////////////////////////

// Inputs da Estratégia
pmax = input.int(90, minval=0, maxval=100, title="Estocastico Alvo - Para Short")
pmin = input.int(10, minval=0, maxval=100, title="Estocastico Alvo - Para Buy ")

parcial = input(title="Parcial ? ", defval=true)
p_gain = input.int(150, minval=0, maxval=1000, title="Pontos para Gain ")
p_loss = input.int(150, minval=0, maxval=1000, title="Pontos para Loss")
p_parcial = input.int(50, minval=0, maxval=100, title="Pontos para Parcial ")

// puxando os indicadores que usaremos 
estoc = ta.stoch(close,high,low,5)

if (estoc >=pmax and close < open)
    strategy.entry("Vende", strategy.short ,qty = 2)


if (estoc <=pmax and close > open)
    strategy.entry("Compra", strategy.long ,qty  =  2 )


pm_ativo = strategy.opentrades.entry_price(0)

if strategy.position_size > 0 and parcial// Posicionado na compra 
    if strategy.position_size == 2 // Mão cheia
        if close < pm_ativo - 100
            strategy.exit("Fecha Compra", "Compra", loss=p_loss , qty  =  2 )
        if close > pm_ativo + 50
            strategy.exit("Fecha Compra", "Compra", profit=p_gain , qty  =  1 )
    if strategy.position_size == 1// Mão cheia
        if close < pm_ativo 
            strategy.exit("Fecha Compra", "Compra", loss=0 , qty  =  1 )
        if close > pm_ativo + 100
            strategy.exit("Fecha Compra", "Compra", profit= p_gain * 1.5 , qty  =  1 )    
    
if strategy.position_size < 0 and parcial // Posicionado na Venda 
    if strategy.position_size == -2 // Mão cheia
        if close > pm_ativo - 100
            strategy.exit("Fecha Venda", "Vende", loss=p_loss , qty  =  2 )
        if close < pm_ativo + 50
            strategy.exit("Fecha Venda", "Vende", profit=p_gain , qty  =  1 )
    if strategy.position_size == -1// Mão cheia
        if close > pm_ativo 
            strategy.exit("Fecha Venda", "Vende", loss=0 , qty  =  1 )
        if close < pm_ativo + 100
            strategy.exit("Fecha Venda", "Vende", profit=p_gain*1.5 , qty  =  1 )    
    
if strategy.position_size > 0 and parcial == false // Sem Parcial 
    strategy.exit("Fecha Compra", "Compra", loss=p_loss , profit = p_gain , qty  =  2 )
if strategy.position_size < 0 and parcial == false // Sem Parcial 
    strategy.exit("Fecha Venda", "Vende", loss=p_loss , profit = p_gain , qty  =  2 )