
이 전략은 이동평균선 교차 신호와 ATR 위험 관리를 결합한 추세 추종 거래 시스템입니다. 이 전략은 빠르고 느린 이동 평균선의 교차를 통해 시장 동향을 포착하고, ATR 지표를 사용하여 손절매 및 수익 수준을 동적으로 조정하여 거래 위험을 정확하게 제어합니다. 이 전략에는 계좌 자본과 사전 설정된 위험 매개변수에 따라 포지션 크기를 자동으로 조정하는 자금 관리 모듈도 포함되어 있습니다.
전략의 핵심 논리는 다음과 같은 핵심 구성 요소를 기반으로 합니다.
이 전략은 이동 평균선 교차를 통해 추세를 포착하고 이를 ATR 동적 위험 제어와 결합하여 완전한 추세 추적 거래 시스템을 구축합니다. 이 전략의 강점은 적응성과 위험 관리 능력에 있지만, 변동성이 큰 시장에서는 성과가 좋지 않을 수 있습니다. 추세 필터를 추가하고 자금 관리 시스템을 최적화하면 전략의 전반적인 성과를 개선할 수 있습니다.
/*backtest
start: 2024-12-06 00:00:00
end: 2025-01-04 08:00:00
period: 3h
basePeriod: 3h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © davisash666
//@version=5
strategy("Trend-Following Strategy", overlay=true)
// Inputs for strategy parameters
timeframe = input.timeframe("D", "Timeframe")
risk_tolerance = input.float(2.0, "Risk Tolerance (%)", step=0.1) / 100
capital_allocation = input.float(200, "Capital Allocation (%)", step=1) / 100
// Technical indicators (used to emulate machine learning)
ma_length_fast = input.int(10, "Fast MA Length")
ma_length_slow = input.int(50, "Slow MA Length")
atr_length = input.int(14, "ATR Length")
atr_multiplier = input.float(1.5, "ATR Multiplier")
// Calculations
fast_ma = ta.sma(close, ma_length_fast)
slow_ma = ta.sma(close, ma_length_slow)
atr = ta.atr(atr_length)
// Entry and exit conditions
long_condition = ta.crossover(fast_ma, slow_ma)
short_condition = ta.crossunder(fast_ma, slow_ma)
// Risk management
stop_loss_long = close - (atr * atr_multiplier)
stop_loss_short = close + (atr * atr_multiplier)
take_profit_long = close + (atr * atr_multiplier)
take_profit_short = close - (atr * atr_multiplier)
// Capital allocation
position_size = strategy.equity * capital_allocation
// Execute trades
if long_condition
strategy.entry("Long", strategy.long, qty=position_size / close)
strategy.exit("Take Profit/Stop Loss", "Long", stop=stop_loss_long, limit=take_profit_long)
if short_condition
strategy.entry("Short", strategy.short, qty=position_size / close)
strategy.exit("Take Profit/Stop Loss", "Short", stop=stop_loss_short, limit=take_profit_short)
// Plotting for visualization
plot(fast_ma, color=color.green, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")
plot(stop_loss_long, color=color.blue, title="Stop Loss (Long)", linewidth=1, style=plot.style_cross)
plot(take_profit_long, color=color.purple, title="Take Profit (Long)", linewidth=1, style=plot.style_cross)