
この戦略は、移動平均、RSI インジケーター、およびトレーリング ストップ ロスに基づいた定量的な取引システムです。テクニカル分析におけるトレンド追跡とモメンタム指標を組み合わせ、厳格なエントリー条件とエグジット条件を設定することでリスク管理された取引を実現します。この戦略の核となるロジックは、上昇トレンドで市場に参入するための売られ過ぎの機会を探し、トレーリングストップロスを使用して利益を保護することです。
この戦略では、200 日単純移動平均 (SMA) をトレンド判断の基準として使用し、相対力指数 (RSI) と組み合わせて取引シグナルを生成します。具体的には:
これは、完全な構造と明確なロジックを備えた定量的な取引戦略です。複数のテクニカル指標を組み合わせ、リスクをコントロールしながら安定したリターンを追求します。最適化の余地はあるものの、基本的なフレームワークは実用性と拡張性に優れています。この戦略は中長期投資家に適しており、さまざまな市場環境への適応性に優れています。
/*backtest
start: 2025-01-09 00:00:00
end: 2025-01-16 00:00:00
period: 15m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("200 SMA Crossover Strategy", overlay=false)
// Define inputs
smaLength = input.int(200, title="SMA Length")
rsiLength = input.int(14, title="RSI Length")
rsiThreshold = input.float(40, title="RSI Threshold")
trailStopPercent = input.float(5.0, title="Trailing Stop Loss (%)")
waitingPeriod = input.int(10, title="Waiting Period (Days)")
// Calculate 200 SMA
sma200 = ta.sma(close, smaLength)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Plot the 200 SMA and RSI
plot(sma200, color=color.blue, linewidth=2, title="200 SMA")
plot(rsi, color=color.purple, title="RSI", display=display.none)
// Define buy and sell conditions
var isLong = false
var float lastExitTime = na
var float trailStopPrice = na
// Explicitly declare timeSinceExit as float
float timeSinceExit = na(lastExitTime) ? na : (time - lastExitTime) / (24 * 60 * 60 * 1000)
canEnter = na(lastExitTime) or timeSinceExit > waitingPeriod
buyCondition = close > sma200 and rsi < rsiThreshold and canEnter
if (buyCondition and not isLong)
strategy.entry("Buy", strategy.long)
trailStopPrice := na
isLong := true
// Update trailing stop loss if long
if (isLong)
trailStopPrice := na(trailStopPrice) ? close * (1 - trailStopPercent / 100) : math.max(trailStopPrice, close * (1 - trailStopPercent / 100))
// Check for trailing stop loss or sell condition
if (isLong and (close < trailStopPrice or close < sma200))
strategy.close("Buy")
lastExitTime := time
isLong := false
// Plot buy and sell signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=(isLong and close < trailStopPrice) or close < sma200, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")