
A estratégia é um sistema de negociação de reversão de tendência baseado no desvio do movimento do gráfico em forma de coluna do MACD. Capta sinais de reversão de mercado analisando a relação entre a mudança de forma da linha K e a mudança de movimento do gráfico em forma de coluna do MACD. A idéia central da estratégia é negociar de reversão quando há sinais de diminuição do movimento do mercado, para que o layout antecipado quando a tendência está prestes a ser revertida.
A lógica de negociação da estratégia é dividida em duas direções: Condições de vazio: quando há uma grande linha de sol ((preço de fechamento acima do preço de abertura), e sua entidade é maior do que a linha K anterior, e o gráfico em forma de coluna MACD apresenta uma tendência descendente em 3 ciclos consecutivos, indicando que a força de oscilação ascendente está diminuindo, o sistema emite um sinal de vazio 。 Fazer mais condições: quando há uma linha negativa maior (preço de fechamento abaixo do preço de abertura), e sua entidade é maior do que a linha K anterior, e o gráfico em forma de coluna MACD apresenta uma tendência ascendente por 3 ciclos consecutivos, indicando que a tendência de queda está diminuindo, o sistema emite mais sinais. A gestão de posições utiliza um mecanismo de liquidação de sinais de oponentes, ou seja, quando surge um sinal de negociação na direção oposta, liquida-se a posição atual. A estratégia não configura stop loss e stop loss, dependendo totalmente do sinal para gerenciar a posição.
A estratégia é caracterizada pela simplicidade de operação e pela clareza de sinais. Embora haja um certo risco, a estabilidade e a lucratividade da estratégia podem ser significativamente aumentadas por meio de medidas razoáveis de otimização e gerenciamento de risco. A estratégia é especialmente adequada para um mercado de tendências e pode ser uma parte importante do sistema de negociação.
/*backtest
start: 2024-11-10 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("MACD Momentum Reversal Strategy", overlay=true, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === MACD Calculation ===
fastLength = input.int(12, "MACD Fast Length")
slowLength = input.int(26, "MACD Slow Length")
signalLength = input.int(9, "MACD Signal Length")
[macdLine, signalLine, histLine] = ta.macd(close, fastLength, slowLength, signalLength)
// === Candle Properties ===
bodySize = math.abs(close - open)
prevBodySize = math.abs(close[1] - open[1])
candleBigger = bodySize > prevBodySize
bullishCandle = close > open
bearishCandle = close < open
// === MACD Momentum Conditions ===
// For bullish candles: if the MACD histogram (normally positive) is decreasing over the last 3 bars,
// then the bullish momentum is fading – a potential short signal.
macdLossBullish = (histLine[2] > histLine[1]) and (histLine[1] > histLine[0])
// For bearish candles: if the MACD histogram (normally negative) is increasing (moving closer to zero)
// over the last 3 bars, then the bearish momentum is fading – a potential long signal.
macdLossBearish = (histLine[2] < histLine[1]) and (histLine[1] < histLine[0])
// === Entry Conditions ===
// Short entry: Occurs when the current candle is bullish and larger than the previous candle,
// while the MACD histogram shows fading bullish momentum.
enterShort = bullishCandle and candleBigger and macdLossBullish
// Long entry: Occurs when the current candle is bearish and larger than the previous candle,
// while the MACD histogram shows fading bearish momentum.
enterLong = bearishCandle and candleBigger and macdLossBearish
// === Plot the MACD Histogram for Reference ===
plot(histLine, title="MACD Histogram", color=color.blue, style=plot.style_histogram)
// === Strategy Execution ===
// Enter positions based on conditions. There is no stop loss or take profit defined;
// positions remain open until an opposite signal occurs.
if (enterShort)
strategy.entry("Short", strategy.short)
if (enterLong)
strategy.entry("Long", strategy.long)
// Exit conditions: close an existing position when the opposite signal appears.
if (strategy.position_size > 0 and enterShort)
strategy.close("Long")
if (strategy.position_size < 0 and enterLong)
strategy.close("Short")