この戦略は,移動平均 ((MA),相対的に強い指数 ((RSI) と平均リアル波幅 ((ATR) などの技術分析ツールと組み合わせて,市場のトレンドの機会を捉えることを目的としています. 戦略は,双平線交差によってトレンドの方向を判断し,RSI指標を使用して取引信号を動量でフィルターし,ATRを損失の基準として使用し,リスクを制御します.
この戦略の核心は,2つの異なる周期の移動平均 (快線と慢線) の交差を用いて市場トレンドを判断することである.快線上を慢線に横切ると,上昇傾向を示し,戦略は多多信号を生成する.逆に,快線下を慢線に横切ると,下降傾向を示し,戦略は多空信号を生成する.
取引信号の信頼性を高めるために,戦略は,動力のフィルターとしてRSI指標を導入した. RSIが特定の値 (例えば50) よりも高いときだけ,多ポジションを開くことが許可され,RSIがその値より低いときだけ,空いているポジションを開くことが許可される.
さらに,戦略はATRをストップベースとして採用し,近年の価格の変動幅に応じてストップポイントを動的に調整し,異なる市場状態に適応する.この自己適応のストップ方式は,トレンドが不明なときに迅速にストップし,撤回を制御し,トレンドが強くなるとより大きな利益の余地を与え,戦略の利益を向上させる.
この戦略は,トレンドフォローと動量フィルターの有機的な組み合わせにより,市場におけるトレンド性機会を捉えると同時に,リスクをより良くコントロールする.戦略の論理は明確で,実行しやすく,最適化できる.しかし,実用的な応用では,依然として,波動的な市場リスクとパラメータリスクに注意し,市場特性と独自のニーズに応じて,柔軟に調整し,最適化する戦略が必要である.全体的に,これはトレンド把握とリスク管理の両方を兼ね備えたバランスの取れた戦略であり,さらなる探索と実践に値する.
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend-Following Strategy with MACD and RSI Filter", overlay=true)
// Input variables
fastLength = input(12, title="Fast MA Length")
slowLength = input(26, title="Slow MA Length")
signalLength = input(9, title="Signal Line Length")
stopLossPct = input(1.0, title="Stop Loss %") / 100
rsiLength = input(14, title="RSI Length")
rsiThreshold = input(50, title="RSI Threshold")
// Moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)
// RSI
rsi = ta.rsi(close, rsiLength)
// Entry conditions with RSI filter
bullishSignal = ta.crossover(macdLine, signalLine) and rsi > rsiThreshold
bearishSignal = ta.crossunder(macdLine, signalLine) and rsi < rsiThreshold
// Calculate stop loss levels
longStopLoss = ta.highest(close, 10)[1] * (1 - stopLossPct)
shortStopLoss = ta.lowest(close, 10)[1] * (1 + stopLossPct)
// Execute trades
strategy.entry("Long", strategy.long, when=bullishSignal)
strategy.entry("Short", strategy.short, when=bearishSignal)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
strategy.exit("Exit Short", "Short", stop=shortStopLoss)
// Plotting signals
plotshape(bullishSignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bullish Signal")
plotshape(bearishSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bearish Signal")
// Plot MACD
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// Plot RSI
hline(rsiThreshold, "RSI Threshold", color=color.gray)
plot(rsi, color=color.purple, title="RSI")