
A estratégia combina dois indicadores técnicos, o MACD e o RSI, para determinar a hora de negociação, usando o sinal de cruzamento do MACD e o sinal de sobrevenda do RSI. Além disso, a estratégia também introduz a média móvel ponderada (WMA) como julgamento auxiliar para aumentar a confiabilidade da estratégia. A estratégia funciona em um período de 1 hora, quando o MACD aparece em um forco de ouro e o RSI é maior que 50 e abre mais posições, quando o MACD aparece em um forco morto e o RSI é menor que 50 e abre mais posições.
O centro da estratégia é a combinação de MACD e RSI, dois indicadores técnicos. O MACD é composto por um diferencial entre a linha rápida (mediana móvel de curto prazo) e a linha lenta (mediana móvel de longo prazo), que pode refletir a mudança de tendência do mercado. Quando a linha rápida atravessa a linha lenta, forma-se um furco de ouro, indicando uma tendência ascendente, e, ao contrário, forma-se um furco morto, indicando uma tendência descendente. O RSI é um indicador que mede o estado de sobrevenda do mercado, quando o RSI é maior que 70, indica que o mercado está em um estado de sobrevenda e pode enfrentar o risco de retorno; Quando o RSI é menor que 30, indica que o mercado está em um estado de sobrevenda e pode aguardar uma oportunidade de rebote.
A estratégia combina o MACD e o RSI, usando a avaliação de tendência do MACD e a avaliação de superbúsculo do RSI, para capturar com mais precisão o momento de negociação. Além disso, a estratégia também introduziu a média móvel ponderada (WMA) como avaliação auxiliar, que dá mais importância aos preços recentes do que a média móvel comum e é capaz de refletir as mudanças de preços com mais sensibilidade.
Além disso, a estratégia também define variáveis de vários períodos de tempo (como 15 minutos, 30 minutos, 1 hora, 2 horas, etc.) para julgar a mudança de tendência em diferentes escalas de tempo. Esta abordagem de análise de múltiplos períodos de tempo pode ajudar a estratégia a ter uma compreensão mais abrangente das tendências do mercado e melhorar a precisão de suas decisões.
A estratégia combina MACD e RSI, dois indicadores técnicos eficazes, e introduz WMA como julgamento auxiliar, para tomar decisões de negociação em um período de 1 hora. A lógica da estratégia é clara, fácil de entender e implementar, pode capturar melhor as tendências do mercado e o estado de sobrecompra e sobrevenda, e tem uma certa viabilidade. No entanto, a estratégia também possui algumas limitações e riscos, como atraso, um único período de tempo, falta de controle de risco, etc.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Improved MACD and RSI Trading Strategy", overlay=true, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.01, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// MACD 設置
fast_length = input(12, title="MACD Fast Length")
slow_length = input(26, title="MACD Slow Length")
signal_smoothing = input(9, title="MACD Signal Smoothing")
// RSI 設置
input_rsi_length = input.int(14, title="RSI Length")
input_rsi_source = input(close, "RSI Source")
RSI = ta.rsi(input_rsi_source, input_rsi_length)
// 計算MACD和信號線
[macdLine, signalLine, _] = ta.macd(close, fast_length, slow_length, signal_smoothing)
// 自然交易理論:利用MACD和RSI的結合
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
maTypeInput = input.string("SMA", title="Moving Average Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="Moving Average Length", group="MA Settings")
macdMA = ma(macdLine, maLengthInput, maTypeInput)
// 設置交易信號
longCondition = ta.crossover(macdLine, signalLine) and macdLine > macdMA and RSI < 70
shortCondition = ta.crossunder(macdLine, signalLine) and macdLine < macdMA and RSI > 30
// 定義時間框架
tf_15m = ta.change(RSI, 15) > 0 ? 1 : 0
tf_30m = ta.change(RSI, 30) > 0 ? 1 : 0
tf_1h = ta.change(RSI, 60) > 0 ? 1 : 0
tf_2h = ta.change(RSI, 120) > 0 ? 1 : 0
tf_4h = ta.change(RSI, 240) > 0 ? 1 : 0
tf_6h = ta.change(RSI, 360) > 0 ? 1 : 0
tf_8h = ta.change(RSI, 480) > 0 ? 1 : 0
tf_12h = ta.change(RSI, 720) > 0 ? 1 : 0
tf_1d = ta.change(RSI, 1440) > 0 ? 1 : 0
// 設置開倉、平倉和空倉條件
if (longCondition and tf_1h and RSI > 50)
strategy.entry("Long", strategy.long)
if (shortCondition and tf_1h and RSI < 50)
strategy.entry("Short", strategy.short)
if (tf_1h and RSI > 70)
strategy.close("Long")
if (tf_1h and RSI < 30)
strategy.close("Short")
// 加入其他策略
// 定義加權平均價格
wma(source, length) =>
wma = 0.0
sum = 0.0
sum_wts = 0.0
for i = 0 to length - 1
wts = (length - i) * (length - i)
sum := sum + source[i] * wts
sum_wts := sum_wts + wts
wma := sum / sum_wts
wmaLength = input.int(20, title="WMA Length", group="Other Strategies")
wmaValue = wma(close, wmaLength)
// 設置交易信號
longWMACondition = close > wmaValue
shortWMACondition = close < wmaValue
if (longWMACondition and tf_1h and RSI > 50)
strategy.entry("Long WMA", strategy.long)
if (shortWMACondition and tf_1h and RSI < 50)
strategy.entry("Short WMA", strategy.short)
if (tf_1h and RSI > 70)
strategy.close("Long WMA")
if (tf_1h and RSI < 30)
strategy.close("Short WMA")
// 繪製MACD和RSI
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.red, title="Signal Line")