빠르고 느린 이중 이동 평균 거래 전략


생성 날짜: 2023-10-27 16:41:24 마지막으로 수정됨: 2023-10-27 16:41:24
복사: 0 클릭수: 691
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

빠르고 느린 이중 이동 평균 거래 전략

개요

쌍평선 거래 전략은 빠른 이동 평균과 느린 이동 평균을 계산하여 두 개의 이동 평균의 교차 상황에 따라 거래 신호를 생성합니다. 빠른 이동 평균 위에 느린 이동 평균을 통과 할 때 다중 머리 전략을 취하고, 빠른 이동 평균 아래에 느린 이동 평균을 통과 할 때 공백 전략을 취합니다. 이 전략은 추세 거래와 역전 거래 모두에 사용할 수 있습니다.

전략 원칙

이 전략은 먼저 빠른 이동 평균의 길이를 maFastLength와 느린 이동 평균의 길이를 maSlowLength로 설정한다. 그리고는 빠른 이동 평균 (fastMA) 과 느린 이동 평균 (slowMA) 을 계산한다. 빠른 이동 평균은 가격 변화에 더 민감하게 반응하여 현재 트렌드를 판단할 수 있다. 느린 이동 평균은 가격 변화에 더 느리게 반응하여 트렌드 방향을 판단할 수 있다.

빠른 이동 평균 상에서 느린 이동 평균을 통과 할 때, 다중 전략을 취하여 goLong () 신호를 생성하십시오. 빠른 이동 평균 아래에서 느린 이동 평균을 통과 할 때, 평형 포지션은 다중을 수행하여 killLong () 신호를 생성하십시오.

다중 전략 longonly, 포커스 전략 shorting, 또는 양방향 거래 swapping 을 선택할 수 있습니다.

다중 전략 할 때, goLong() 신호가 발령될 때 더 많은 포지션을 열고, killLong() 신호가 발령될 때 평소 포지션을 한다.

공백 전략은, killLong () 신호가 발송될 때 공백을 열고, goLong () 신호가 발송될 때 평정한다.

양방향 거래할 때, goLong () 신호가 발송될 때 더 많은 포지션을 열고, killLong () 신호가 발송될 때 더 많은 포지션을 청산하고 빈 포지션을 열는다.

또한, 전략은 스톱로스, 스톱로스 추적, 트레이드 알림 등의 기능을 설정하여 사용 여부를 유연하게 선택할 수 있습니다.

전략적 이점

  1. 전략은 간단하고 이해하기 쉽고 실행하기 쉽습니다.

  2. 자유로이 거래할 수 있습니다. 상장, 상장 또는 양방향 거래도 가능합니다.

  3. 스톱로스, 스톱로스를 추적하는 등의 리스크 관리 기능을 사용할 수 있는 유연한 선택

  4. 트랜잭션 메시지를 사용자 정의하고 트랜잭션 행동을 실시간으로 알릴 수 있습니다.

  5. 급속한 평균선 전략은 시장의 추세 변화에 민감하며, 강한 추세를 잡을 수 있다.

  6. 전략의 매개 변수는 조정할 수 있으며, 시장에 따라 매개 변수를 조정할 수 있으며, 적응력이 강하다.

전략적 위험

  1. 시장이 명확한 추세가 없을 때, 더 많은 가짜 신호가 발생할 수 있으며, 과도한 거래가 발생할 수 있습니다.

  2. 평선 시스템은 급격한 사건에 민감하지 않으며, 급격한 기회를 놓칠 수 있다.

  3. 평균선 변수를 합리적으로 선택해야 하며, 변수를 잘못 선택하면 전략 효과에 영향을 줄 수 있다.

  4. 전략적 신호를 엄격히 준수하여 임의의 거래가 발생하지 않도록 해야 합니다.

  5. 전략적 수익성에 대한 거래 비용의 영향에 주목할 필요가 있습니다.

전략 최적화 방향

  1. 거래 신호를 확인하기 위해 RSI와 같은 다른 지표를 도입할 수 있습니다.

  2. 매개 변수 최적화 기능을 설정하여 최적의 매개 변수 조합을 자동으로 찾습니다.

  3. 동적 스톱로드를 설정하여 수익을 고정하고 스톱로드를 적절하게 조정할 수 있습니다.

  4. 트렌드 방향을 판단하는 데 도움이 되는 기계 학습 모형을 추가할 수 있습니다.

  5. 트레이딩 트레이딩을 통해 트레이딩 트레이더가 트레이딩 트레이딩 트레이딩을 통해 트레이딩 트레이딩을 수행할 수 있습니다

요약하다

쌍방향 거래 전략은 전체적으로 간단하고 실용적이며, 시장 추세 변화에 민감하며, 강한 추세로 인한 거래 기회를 잡을 수 있습니다. 그러나 추세없는 시장의 잘못된 거래를 방지하고, 다른 시장 환경에 적응하기 위해 파라미터를 적절히 조정하는 데 주의를 기울여야합니다. 또한, 적절한 보조 기술 지표 및 최적화 기능을 추가하면 전략의 안정성과 적응성을 더욱 강화 할 수 있습니다.

전략 소스 코드
/*backtest
start: 2022-10-20 00:00:00
end: 2023-10-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy("SMA Strategy", shorttitle="SMA Strategy", overlay=true, pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// === Inputs ===
// short ma
maFastSource = input(defval=close, title="Fast MA Source")
maFastLength = input(defval=3, title="Fast MA Period", minval=1)

// long ma
maSlowSource = input(defval=close, title="Slow MA Source")
maSlowLength = input(defval=9, title="Slow MA Period", minval=1)

// Trade direction
shorting = input(defval=false, title="Short only?")
longonly = input(defval=true, title="Long only?")
swapping = input(defval=false, title="Swap orders?")
// risk management
useStop = input(defval=false, title="Use Initial Stop Loss?")
slPoints = input(defval=25, title="Initial Stop Loss Points", minval=1)
useTS = input(defval=false, title="Use Trailing Stop?")
tslPoints = input(defval=120, title="Trail Points", minval=1)
useTSO = input(defval=false, title="Use Offset For Trailing Stop?")
tslOffset = input(defval=20, title="Trail Offset Points", minval=1)

// Messages for buy and sell
message_long_entry  = input("Long entry message", title="Long entry message")
message_long_exit   = input("Long exit message", title="Long exit message")
message_short_entry = input("Short entry message", title="Short entry message")
message_short_exit  = input("Short exit message", title="Short exit message")

// Calculate start/end date and time condition
startDate  = input(timestamp("2021-01-01T00:00:00"), type = input.time)
finishDate = input(timestamp("2021-12-31T00:00:00"), type = input.time)
 
time_cond  = true
// === Vars and Series ===
fastMA = sma(maFastSource, maFastLength)
slowMA = sma(maSlowSource, maSlowLength)

plot(fastMA, color=color.blue)
plot(slowMA, color=color.purple)

goLong() =>
    crossover(fastMA, slowMA)
killLong() =>
    crossunder(fastMA, slowMA)
    
// Long only
if longonly
    strategy.entry("Buy", strategy.long, when=goLong() and time_cond, alert_message = message_long_entry)
    strategy.close("Buy", when=killLong() and time_cond, alert_message = message_long_exit)

// Short only
if shorting
    strategy.entry("Sell", strategy.short, when=killLong() and time_cond, alert_message = message_short_entry)
    strategy.close("Sell", when=goLong() and time_cond, alert_message = message_short_exit)
    
// Order Swapping
if swapping
    strategy.entry("Buy", strategy.long, when=goLong() and time_cond, alert_message = message_long_entry)
    strategy.entry("Sell", strategy.short, when=killLong() and time_cond, alert_message = message_short_entry)

if useStop
    strategy.exit("XLS", from_entry="Buy", stop=strategy.position_avg_price / 1.08, alert_message = message_long_exit)
    strategy.exit("XSS", from_entry="Sell", stop=strategy.position_avg_price * 1.08, alert_message = message_short_exit)