
이 전략은 MACD와 RSI의 두 가지 기술 지표를 결합하여 MACD의 교차 신호와 RSI의 오버 바이 오버 시드를 사용하여 거래 시간을 판단합니다. 동시에, 전략은 전략의 신뢰성을 높이기 위해 중화 이동 평균 ((WMA) 을 보조 판단으로 도입합니다. 전략은 1 시간 시간 프레임에서 작동합니다. MACD의 금색이 나타나고 RSI가 50보다 크면 더 많은 포지션을 열고, MACD의 사각이 나타나고 RSI가 50보다 작으면 더 많은 포지션을 열고, MACD의 사각이 나타나고 RSI가 50보다 작으면 더 많은 포지션을 열고, RSI가 70보다 크면 더 많은 포지션을 열고, RSI가 30보다 적은 포지션을 열고 있습니다.
이 전략의 핵심은 MACD와 RSI 두 가지 기술 지표의 결합 사용이다. MACD는 빠른 선 ((단기 이동 평균) 과 느린 선 ((장기 이동 평균) 의 차원으로 구성되어 시장의 추세 변화를 반영할 수 있다. 빠른 선에서 느린 선을 통과 할 때, 금 포크가 형성되어 상승 추세를 나타내고, 반대로 죽은 포크가 형성되어 하락 추세를 나타낸다. RSI는 시장의 과매 과매 상태를 측정하는 지표이며, RSI가 70보다 크면 시장이 과매 상태에 있으며 리콜의 위험이 있음을 나타냅니다. RSI가 30보다 작으면 시장이 과매 상태에 있으며 반발 기회를 맞이 할 수 있음을 나타냅니다.
이 전략은 MACD와 RSI를 결합하여 MACD의 트렌드 판단과 RSI의 오버 바이 오버 셀 판단을 사용하여 거래 시기를 더 정확하게 파악할 수 있습니다. 또한, 전략은 중화 이동 평균 ((WMA) 을 보조 판단으로 도입합니다. WMA는 일반 이동 평균에 비해 최근 가격에 더 많은 중점을 두어 가격 변화를 더 민감하게 반영 할 수 있습니다.
또한, 전략은 여러 시간 프레임의 변수를 설정합니다 (예: 15 분, 30 분, 1 시간, 2 시간 등) 서로 다른 시간 스케일의 트렌드 변화를 판단하기 위해. 이러한 여러 시간 프레임의 분석 방법은 전략이 시장 추세를 더 포괄적으로 파악하고 의사 결정의 정확성을 높이는 데 도움이 될 수 있습니다.
이 전략은 MACD와 RSI의 두 가지 유효한 기술 지표를 결합하고 WMA를 보조 판단으로 도입하여 1 시간 시간 프레임 내에서 거래 결정을 내립니다. 전략 논리는 명확하고 이해하기 쉽고 실행할 수 있으며 시장 추세와 과매매 상황을 잘 파악할 수 있습니다. 그러나 전략에는 지연성, 단일 시간 프레임, 위험 제어 부족 등과 같은 제한과 위험이 있습니다.
/*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")