
이 전략은 간단한 이동 평균 (SMA) 의 금포스 사다리 원칙에 기초하여 설계되었다. 이 전략은 두 개의 SMA, 즉 빠른 SMA와 느린 SMA를 사용하여 빠른 SMA가 아래쪽에서 느린 SMA를 돌파하면 구매 신호를 생성하고 빠른 SMA가 위쪽에서 느린 SMA를 넘어서는 경우 판매 신호를 생성한다.
이 전략은 주로 두 개의 SMA 지표선에 의존한다. 그 중, 빠른 SMA 기간 동안 짧은 설정으로 가격 변화를 더 빨리 포착할 수 있다. 느린 SMA 기간 동안 더 긴 설정으로 일부 잡음을 필터링 할 수 있다. 빠른 SMA가 아래쪽에서 느린 SMA를 가로질러서는 단기 가격 상승 속도가 빠르다는 것을 의미하며, 구매 신호를 발생시킨다. 빠른 SMA가 위쪽에서 아래쪽에서 느린 SMA를 가로질러서는 단기 가격 하락 속도가 빠르다는 것을 의미하며, 판매 신호를 발생시킨다.
다른 SMA 주기 파라미터를 설정함으로써, 전략의 파라미터를 어느 정도 조정할 수 있으며, 다른 시장 환경에 적응할 수 있다. 동시에, 이 전략은 재검토의 시간 범위를 설정할 수 있으며, 역사적인 데이터에 전략 파라미터를 테스트하는 것이 편리하다.
위와 같은 위험에는 다음과 같은 조치를 취할 수 있습니다.
이 전략은 전형적인 트렌드 추적 전략에 속한다. 간단한 쌍평선 교차 원리를 적용하여, 파라미터를 적절하게 설정하는 전제 조건에서, 더 나은 추적 효과를 얻을 수 있다. 그러나 SMA 자체는 다소 뒤처져 있어, 트렌드의 강도를 판단할 수 없다. 따라서, 실제 응용에서는, 자동화된 파라미터 최적화 및 위험 제어 수단과 함께 지표 포트폴리지를 형성하는 다른 보조 도구를 도입할 필요가 있다.
/*backtest
start: 2023-12-17 00:00:00
end: 2023-12-18 19:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//strategy(title="MA Cross Entry & Exit w/Date Range", overlay=true, initial_capital=10000, currency='USD')
strategy(title="SMA Cross Entry & Exit Strategy", overlay=true)
// Credit goes to this developer for the "Date Range Code"
// https://www.tradingview.com/script/62hUcP6O-How-To-Set-Backtest-Date-Range/
// === GENERAL INPUTS ===
// short ma
maFastSource = input(defval = open, title = "Fast MA Source")
maFastLength = input(defval = 36, title = "Fast MA Period", minval = 1)
// long ma
maSlowSource = input(defval = open , title = "Slow MA Source")
maSlowLength = input(defval = 46, title = "Slow MA Period", minval = 1)
// === SERIES SETUP ===
// a couple of ma's..
maFast = sma(maFastSource, maFastLength)
maSlow = sma(maSlowSource, maSlowLength)
// === PLOTTING ===
fast = plot(maFast, title = "Fast MA", color = red, linewidth = 2, style = line, transp = 30)
slow = plot(maSlow, title = "Slow MA", color = green, linewidth = 2, style = line, transp = 30)
// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2018, title = "From Year", minval = 2017)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)
// === FUNCTION EXAMPLE ===
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
// === LOGIC ===
//enterLong = crossover(maFast, maSlow)
//exitLong = crossover(maSlow, maFast)
enterLong = crossover(maSlow, maFast)
exitLong = crossover(maFast, maSlow)
// Entry //
strategy.entry(id="Long Entry", long=true, when=window() and enterLong)
strategy.entry(id="Short Entry", long=false, when=window() and exitLong)
// === FILL ====
fill(fast, slow, color = maFast > maSlow ? green : red)