
Chiến lược này thuộc về chiến lược theo dõi xu hướng đơn giản bằng cách tính toán EMA đường nhanh và EMA đường chậm và so sánh mối quan hệ lớn của hai EMA để xác định xu hướng của thị trường. Khi EMA đường nhanh vượt qua EMA đường chậm, hãy làm nhiều và khi EMA đường nhanh vượt qua EMA đường chậm, hãy làm trống.
Các chỉ số cốt lõi của chiến lược này là EMA đường nhanh và EMA đường chậm. Độ dài EMA đường nhanh được thiết lập là 21 chu kỳ và độ dài EMA đường chậm là 55 chu kỳ. EMA đường nhanh phản ứng nhanh hơn với biến động giá, phản ánh xu hướng ngắn hạn gần đây; EMA đường chậm phản ứng chậm hơn với biến động giá, lọc một số tiếng ồn, phản ánh xu hướng trung và dài hạn.
Khi đường EMA nhanh vượt qua đường EMA chậm, nó cho thấy xu hướng ngắn hạn chuyển sang tăng, xu hướng trung hạn có thể bị đảo ngược, đây là tín hiệu làm nhiều. Khi đường EMA nhanh vượt qua đường EMA chậm, nó cho thấy xu hướng ngắn hạn chuyển sang giảm, xu hướng trung hạn có thể bị đảo ngược, đây là tín hiệu làm giảm.
Bằng cách so sánh các EMA nhanh và chậm, bạn có thể bắt được các điểm thay đổi xu hướng trên hai quy mô thời gian ngắn hạn và trung hạn, là một trong những chiến lược theo dõi xu hướng điển hình.
Các biện pháp đối phó với rủi ro:
Chiến lược này được sử dụng để đánh giá xu hướng thị trường thông qua giao thoa giữa đường EMA nhanh và đường EMA chậm, đơn giản, rõ ràng và dễ thực hiện. Đồng thời kết hợp với ATR để thiết lập điểm dừng lỗ, rủi ro có thể kiểm soát được. Bằng cách tối ưu hóa tham số và tăng điều kiện lọc, bạn có thể tăng thêm sự ổn định và lợi nhuận của chiến lược.
/*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)