该策略运用移动平均线差值法判断股价与均线偏离度,并结合零轴交叉系统发出交易信号。基本思路是,当价格从上方接近均线时看跌,当价格从下方接近均线时看涨。
本策略整合均线差值法和零轴交叉判断系统,旨在提高买卖点探测准确性。但仍需进一步优化参数设置,并配合其他指标过滤信号。总的来说,该策略利用简单指标判断效果尚可,可作为基础策略之一运用于实盘。
/*backtest start: 2023-01-19 00:00:00 end: 2024-01-25 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title = "Estratégia diferença menor preço de 8") // Configuração da Média Móvel emaPeriod = 8 ema= ema(close, emaPeriod) ema1= ema(close[1], emaPeriod) lowestEMA = lowest(ema, 8) // Calcula a diferença entre o preço e a média móvel diff = close - ema diff1 = close[1] - ema1 diffLow = ema - lowestEMA //Condições diffZero = diff < 0 diffUnder = diff < diffLow diffUm = diff > 0 Low0 = diffLow == 0 // Sinais de entrada buy_signal = diffUnder and crossover(diff, diff1) sell_signal = diffUm and diffUnder and crossunder(diff, diff1) // Executa as operações de compra/venda if buy_signal strategy.entry("Buy", strategy.long) if sell_signal strategy.exit("Buy") // Plota as linhas plot(0, title="Linha Zero", color=color.gray) plot(diff, title="Diferença", color=color.blue, linewidth=2) plot(diffLow, title="Diferença", color=color.red, linewidth=2)