
이 전략은 이동 평균을 기반으로 한 거래 전략이다. 45 일 이동 평균을 주요 기술 지표로 사용하여, 이동 평균을 깨는 가격의 신호에 따라 구매 및 판매 작업을 수행한다.
가격 상승이 45일 이동 평균을 돌파했을 때, 구매 신호가 생성됩니다. 포지션을 유지한 8일 후, 판매 신호가 생성됩니다. 그 후, 가격이 다시 상승하여 45일 이동 평균을 돌파하면, 구매 신호가 다시 생성됩니다.
이 전략은 다음과 같습니다.
이 전략의 핵심 거래 논리입니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
대책:
이 전략은 다음의 몇 가지 측면에서 최적화될 수 있습니다.
이동 평균 변수를 최적화하여 최적의 변수 조합을 찾습니다. 15일, 30일, 60일 등 다양한 일수 변수를 테스트할 수 있습니다.
포지션 보유 시간을 최적화하여 최적의 포지션 보유 일 수를 찾습니다. 5일, 10일, 15일 등 다양한 포지션 보유 기간을 테스트 할 수 있습니다.
트렌드를 추적하고 리스크를 제어하기 위해 모바일 스톱을 추가합니다. 예를 들어, 트라이얼 스톱 또는 ATR 스톱.
MACD, KDJ 등과 같은 다른 지표에 필터링을 추가하여 가짜 신호를 줄이십시오.
재입장 조건의 최적화, 과도한 거래의 예방. 예를 들어, 냉각 기간의 증가.
다른 시장과 다른 품종의 효과를 테스트하십시오. 매개 변수는 다른 시장에 맞게 최적화해야합니다.
이 이동 평균 횡단 전략은 전체적으로 간단하고 실용적인 트렌드 추적 전략이다. 이동 평균의 트렌드 추적 기능을 활용하여 가격 돌파구와 함께 거래 신호를 생성한다. 장점은 쉽게 구현할 수 있으며, 트레이드-오프는 약간의 오해가 있을 수 있다. 최적화 매개 변수와 보조 기술 지표를 추가하면 더 나은 효과를 얻을 수 있다.
/*backtest
start: 2023-01-16 00:00:00
end: 2024-01-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Moving Average Crossover Strategy", overlay=true)
// Calculate the 45-day moving average
ma_length = 45
ma = ta.sma(close, ma_length)
// Track position entry and entry bar
var bool in_long_position = na
var int entry_bar = na
var int exit_bar = na
// Entry condition: Close price crosses above the 45-day moving average to enter the position
if (not in_long_position and ta.crossover(close, ma) and not na(ma[1]) and close > ma and close[1] < ma[1])
in_long_position := true
entry_bar := bar_index
// Exit condition: Close the position after holding for 8 trading days
if (in_long_position and bar_index - entry_bar >= 8)
in_long_position := false
exit_bar := bar_index
// Re-entry condition: Wait for price to cross over the 45-day moving average again
if (not in_long_position and ta.crossover(close, ma) and not na(ma[1]) and close > ma and close[1] > ma[1] and (na(exit_bar) or bar_index - exit_bar >= 8))
in_long_position := true
entry_bar := bar_index
// Execute long entry and exit
if (in_long_position)
strategy.entry("Long", strategy.long)
if (not in_long_position)
strategy.close("Long")