
この戦略は,MACDとRSIの2つの技術指標を組み合わせて,MACDの交差信号とRSIの超買い超売り信号を使用して取引のタイミングを判断する. 同時に,戦略は,戦略の信頼性を高めるために,重量移動平均 ((WMA) を補助判断として導入する. 戦略は,1時間の時間枠で動作し,MACDが金叉が発生し,RSIが50時より大きいときに多ポジションを開く,MACDが死叉が発生し,RSIが50時より小さいときに空白する.
この戦略の核心は,MACDとRSIの2つの技術指標の組み合わせの使用である.MACDは,快線 (短期移動平均) と慢線 (長期移動平均) の差値で構成され,市場のトレンドの変化を反映することができる.快線で慢線を横切ると,金叉が形成され,上昇傾向を示し,逆に死叉が形成され,下降傾向を示している.RSIは,市場の超買い超売り状態を測定する指標である.RSIが70以上であるときは,市場が超買い状態にあり,リコールのリスクがあることを示し,RSIが30未満であるときは,市場が超売り状態にあり,反発の機会があることを示している.
この戦略は,MACDとRSIを組み合わせて,MACDのトレンド判断とRSIの超買い超売り判断を利用して,取引時間をより正確に把握することができます.また,戦略は,加重移動平均 ((WMA) を補助判断として導入し,WMAは通常の移動平均よりも近期価格に重点を置くことで,価格変化をより敏感に反映することができます.
さらに,戦略は,異なる時間尺度の傾向の変化を判断するために,複数の時間枠の変数 (例えば,15分,30分,1時間,2時間など) を設定しています.この複数の時間枠の分析方法により,戦略は,市場動向をより全面的に把握し,意思決定の正確性を向上させることができます.
この戦略は,MACDとRSIの2つの有効な技術指標を組み合わせて,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")