
이 전략은 두 개의 다른 주기의 이동 평균 ((MA) 을 사용하여 거래 신호를 생성한다. 단기 MA가 아래에서 위쪽으로 장기 MA를 통과하면 구매 신호를 생성하고, 단기 MA가 위쪽으로 장기 MA를 통과하면 판매 신호를 생성한다. 이 전략의 주요 아이디어는 MA의 트렌드 추적 기능을 사용하여 MA를 통해 트렌드 전환을 포착하여 거래를 수행하는 것이다.
쌍평선 교차 전략은 두 개의 다른 주기 MA의 교차로 트렌드 전환을 포착하기 위해 사용되는 간단한 트렌드 추적 전략이다. 이 전략의 장점은 논리적으로 명확하고, 신호가 명확하며, 트렌드 시장에 적합하다. 그러나, 흔들리는 시장에서 이 전략은 더 많은 가짜 신호와 손실 거래를 일으킬 수 있다. 따라서 실제 응용에서는 트렌드 필터링, 스톱 로즈 최적화, 동적 요소 최적화 및 기타 신호와 결합하는 방법을 추가하여 전략의 성능을 개선하고, 그 적응성과 안정성을 향상시킬 수 있다.
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Combined Strategy", overlay=true)
// Moving Averages Length Inputs
short_length = input.int(20, "Short MA Length")
long_length = input.int(50, "Long MA Length")
// Moving Averages
ma_short = ta.sma(close, short_length)
ma_long = ta.sma(close, long_length)
// Buy Condition (Moving Average Crossover)
buy_condition = ta.crossover(ma_short, ma_long)
plotshape(series=buy_condition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
// Sell Condition (Moving Average Crossover)
sell_condition = ta.crossunder(ma_short, ma_long)
plotshape(series=sell_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Strategy Entry and Exit
if (buy_condition)
strategy.entry("Buy", strategy.long)
if (sell_condition)
strategy.entry("Sell", strategy.short)
// Debug statements
if (buy_condition)
label.new(x=bar_index, y=low, text="Buy Signal", color=color.green, style=label.style_label_up)
if (sell_condition)
label.new(x=bar_index, y=high, text="Sell Signal", color=color.red, style=label.style_label_down)