
이 전략은 빠른 라인 EMA와 느린 라인 EMA를 계산하고 두 EMA의 크기와 크기의 관계를 비교하여 시장의 트렌드 방향을 판단하는 간단한 트렌드 추적 전략에 속한다. 빠른 라인 EMA 상에서 느린 라인 EMA를 통과 할 때 더 많이하고, 빠른 라인 EMA 아래에서 느린 라인 EMA를 통과 할 때 공백하는 전형적인 쌍 EMA 골드 크로스 전략에 속한다.
이 전략의 핵심 지표는 패스트 라인 EMA와 슬로우 라인 EMA이다. 패스트 라인 EMA의 길이는 21주기, 슬로우 라인 EMA의 길이는 55주기이다. 패스트 라인 EMA는 최근 단기 추세를 반영하여 가격 변화에 더 빠르게 반응하며, 슬로우 라인 EMA는 가격 변화에 더 느리게 반응하여 중장기 추세를 반영하여 일부 소음을 필터링한다.
빠른 라인 EMA 상에서 느린 라인 EMA를 통과하면 단기 추세가 상승으로 바뀌고 중장기 추세가 전환 될 수 있음을 나타냅니다. 이것은 더 많은 신호입니다. 빠른 라인 EMA 아래에서 느린 라인 EMA를 통과하면 단기 추세가 하락으로 바뀌고 중장기 추세가 전환 될 수 있음을 나타냅니다. 이것은 공백 신호입니다.
빠른 속도 EMA를 비교함으로써, 단기 및 중기 장기 두 시간 스케일의 트렌드 전환점을 포착할 수 있으며, 전형적인 트렌드 추적 전략이다.
위험 대응:
이 전략은 빠른 라인 EMA와 느린 라인 EMA의 교차를 통해 시장 추세를 판단하고, 간단하고 명확하며, 쉽게 구현할 수 있습니다. 또한 ATR과 결합하여 손실을 멈추고, 통제 가능한 위험을 설정합니다. 매개 변수를 최적화하고 필터 조건을 증가시킴으로써 전략의 안정성과 수익성을 더욱 향상시킬 수 있습니다.
/*backtest
start: 2023-10-21 00:00:00
end: 2023-11-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title = "VP Backtester", overlay=false)
// Create General Strategy Inputs
st_yr_inp = input(defval=2017, title='Backtest Start Year')
st_mn_inp = input(defval=01, title='Backtest Start Month')
st_dy_inp = input(defval=01, title='Backtest Start Day')
en_yr_inp = input(defval=2025, title='Backtest End Year')
en_mn_inp = input(defval=01, title='Backtest End Month')
en_dy_inp = input(defval=01, title='Backtest End Day')
// Default Stop Types
fstp = input(defval=false, title="Fixed Perc stop")
fper = input(defval=0.1, title='Percentage for fixed stop', type=float)
atsp = input(defval=true, title="ATR Based stop")
atrl = input(defval=14, title='ATR Length for stop')
atrmsl = input(defval=1.5, title='ATR Multiplier for stoploss')
atrtpm = input(defval=1, title='ATR Multiplier for profit')
// Sessions
asa_inp = input(defval=true, title="Trade the Asian Session")
eur_inp = input(defval=true, title="Trade the European Session")
usa_inp = input(defval=true, title="Trade the US session")
ses_cls = input(defval=true, title="End of Session Close Out?")
// Session Start / End times (In exchange TZ = UTC-5)
asa_ses = "1700-0300"
eur_ses = "0200-1200"
usa_ses = "0800-1700"
in_asa = time(timeframe.period, asa_ses)
in_eur = time(timeframe.period, eur_ses)
in_usa = time(timeframe.period, usa_ses)
strategy.risk.allow_entry_in(strategy.direction.all)
// Set start and end dates for backtest
start = timestamp(st_yr_inp, st_mn_inp, st_dy_inp,00,00)
end = timestamp(en_yr_inp, en_mn_inp, en_dy_inp,00,00)
window() => time >= start and time <= end ? true : false // create function "within window of time"
// Check if we are in a sessions we want to trade
can_trade = asa_inp and not na(in_asa) ? true :
eur_inp and not na(in_eur) ? true :
usa_inp and not na(in_usa) ? true :
false
// atr calc for stop and profit
atr = atr(atrl)
atr_stp_dst_sl = atr * atrmsl
atr_stp_dst_tp = atr * atrtpm
//*************************************************************************************
// Put your strategy/indicator code below
// and make sure to set long_condition=1 for opening a buy trade
// and short_condition for opening a sell trade
//*************************************************************************************
fastInput = input(21)
slowInput = input(55)
fast = ema(close, fastInput)
slow = ema(close, slowInput)
plot(fast, color = red)
plot(slow, color = blue)
long_condition = crossover(fast, slow)
short_condition = crossunder(fast, slow)
//*************************************************************************************
// Trade management with ATR based stop & profit
//*************************************************************************************
if (long_condition and window() )
strategy.entry("Long Entry", strategy.long)
if strategy.position_size <= 0 // Less than as in both direction strat - Could be long before switching
if atsp
atr_stop = open - atr_stp_dst_sl
atr_profit = open + atr_stp_dst_tp
strategy.exit('ATR Long Exit', "Long Entry", stop=atr_stop, limit = atr_profit)
if fstp
stop = open - (open * fper)
strategy.exit('Perc Fixed Long Stop Exit', "Long Entry", stop=stop)
if (short_condition and window() )
strategy.entry("Short Entry",strategy.short)
if strategy.position_size >= 0 // Greater than as in both direction strat - Could be long before switching
if atsp
atr_stop = open + atr_stp_dst_sl
atr_profit = open - atr_stp_dst_tp
strategy.exit('ATR Short Exit', "Short Entry", stop=atr_stop, limit = atr_profit)
if fstp
stop = open + (open * fper)
strategy.exit('Perc Fixed Short Stop Exit', "Short Entry", stop=stop)
strategy.close_all(when=not can_trade and ses_cls)