Chiến lược đột phá Golden Cross EMA kép


Ngày tạo: 2023-12-20 16:34:58 sửa đổi lần cuối: 2023-12-20 16:34:58
sao chép: 1 Số nhấp chuột: 719
1
tập trung vào
1621
Người theo dõi

Chiến lược đột phá Golden Cross EMA kép

Tổng quan

Chiến lược này là một chiến lược theo dõi xu hướng để thực hiện giao dịch Gold Cross và Death Cross dựa trên các đường trung bình di chuyển chỉ số 5 phút và 34 phút ((EMA)). Khi đường nhanh đi qua đường chậm từ phía dưới, hãy mở vị trí dài; khi đường nhanh đi qua đường dài từ phía trên xuống, hãy mở vị trí trống.

Nguyên tắc chiến lược

  1. Dòng nhanh EMA5 và Dòng chậm EMA34 tạo thành tín hiệu giao dịch. EMA5 phản ứng với sự thay đổi gần đây của giá, EMA34 phản ứng với sự thay đổi trung bình của giá.
  2. Khi đường nhanh đi qua đường chậm, nó được chéo cho vàng, cho thấy tình trạng ngắn hạn tốt hơn tình trạng trung hạn, giữ nhiều đơn.
  3. Khi đường nhanh dưới đường chậm, chéo cho cái chết, cho thấy tình hình ngắn hạn tồi tệ hơn so với tình hình trung hạn, giữ vé máy bay.
  4. Cài đặt Stop Loss để khóa lợi nhuận và kiểm soát rủi ro.

Phân tích lợi thế

  1. Sử dụng bộ lọc EMA kép để tránh bị chặn.
  2. Theo dõi xu hướng trung hạn, tăng cơ hội lợi nhuận.
  3. Thiết lập Stop Loss để kiểm soát rủi ro hiệu quả.

Phân tích rủi ro

  1. EMA đôi có tính chậm trễ và có thể bỏ lỡ cơ hội giao dịch ngắn hạn.
  2. Các điểm dừng lỗ được thiết lập quá lớn, nguy cơ tăng lỗ.
  3. Điểm dừng được thiết lập quá nhỏ, không thể tối đa hóa cơ hội kiếm lợi nhuận.

Hướng tối ưu hóa

  1. Tối ưu hóa các tham số EMA, tìm kiếm sự kết hợp tốt nhất.
  2. Tối ưu hóa điểm dừng lỗ, khóa nhiều hơn.
  3. Thêm các bộ lọc cho các chỉ số khác như MACD, KDJ, v.v. để cải thiện độ chính xác của tín hiệu.

Tóm tắt

Chiến lược này tạo ra tín hiệu giao dịch thông qua giao điểm vàng và giao điểm chết của hai đường trung bình di chuyển EMA, và đặt lệnh dừng để kiểm soát rủi ro, là một chiến lược theo dõi xu hướng trung hạn đơn giản và hiệu quả. Tối ưu hóa tham số dừng, giới thiệu các tín hiệu lọc các chỉ số khác có thể tăng thêm khả năng lợi nhuận ổn định của chiến lược.

Mã nguồn chiến lược
/*backtest
start: 2023-11-01 00:00:00
end: 2023-11-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title='[STRATEGY][RS]MicuRobert EMA cross V2', shorttitle='S', overlay=true, pyramiding=0, initial_capital=100000)
USE_TRADESESSION = input(title='Use Trading Session?', type=bool, defval=true)
USE_TRAILINGSTOP = input(title='Use Trailing Stop?', type=bool, defval=true)
trade_session = input(title='Trade Session:',defval='0400-1500', confirm=false)
istradingsession = not USE_TRADESESSION ? false : not na(time('1', trade_session))
bgcolor(istradingsession?gray:na)
trade_size = input(title='Trade Size:', type=float, defval=1)
tp = input(title='Take profit in pips:', type=float, defval=55.0) * (syminfo.mintick*10)
sl = input(title='Stop loss in pips:', type=float, defval=22.0) * (syminfo.mintick*10)
ma_length00 = input(title='EMA length:',  defval=5)
ma_length01 = input(title='DEMA length:',  defval=34)
price = input(title='Price source:',  defval=open)

//  ||--- NO LAG EMA, Credit LazyBear:  ---||
f_LB_zlema(_src, _length)=>
    _ema1=ema(_src, _length)
    _ema2=ema(_ema1, _length)
    _d=_ema1-_ema2
    _zlema=_ema1+_d
//  ||-------------------------------------||

ma00 = f_LB_zlema(price, ma_length00)
ma01 = f_LB_zlema(price, ma_length01)
plot(title='M0', series=ma00, color=black)
plot(title='M1', series=ma01, color=black)

isnewbuy = change(strategy.position_size)>0 and change(strategy.opentrades)>0
isnewsel = change(strategy.position_size)<0 and change(strategy.opentrades)>0

buy_entry_price = isnewbuy ? price : buy_entry_price[1]
sel_entry_price = isnewsel ? price : sel_entry_price[1]
plot(title='BE', series=buy_entry_price, style=circles, color=strategy.position_size <= 0 ? na : aqua)
plot(title='SE', series=sel_entry_price, style=circles, color=strategy.position_size >= 0 ? na : aqua)
buy_appex = na(buy_appex[1]) ? price : isnewbuy ? high : high >= buy_appex[1] ? high : buy_appex[1]
sel_appex = na(sel_appex[1]) ? price : isnewsel ? low : low <= sel_appex[1] ? low : sel_appex[1]
plot(title='BA', series=buy_appex, style=circles, color=strategy.position_size <= 0 ? na : teal)
plot(title='SA', series=sel_appex, style=circles, color=strategy.position_size >= 0 ? na : teal)
buy_ts = buy_appex - sl
sel_ts = sel_appex + sl
plot(title='Bts', series=buy_ts, style=circles, color=strategy.position_size <= 0 ? na : red)
plot(title='Sts', series=sel_ts, style=circles, color=strategy.position_size >= 0 ? na : red)

buy_cond1 = crossover(ma00, ma01) and (USE_TRADESESSION ? istradingsession : true)
buy_cond0 = crossover(price, ma00) and ma00 > ma01 and (USE_TRADESESSION ? istradingsession : true)
buy_entry = buy_cond1 or buy_cond0
buy_close = (not USE_TRAILINGSTOP ? low <= buy_entry_price - sl: low <= buy_ts) or high>=buy_entry_price+tp//high>=last_traded_price + tp or low<=last_traded_price - sl //high >= hh or 
sel_cond1 = crossunder(ma00, ma01) and (USE_TRADESESSION ? istradingsession : true)
sel_cond0 = crossunder(price, ma00) and ma00 < ma01 and (USE_TRADESESSION ? istradingsession : true)
sel_entry = sel_cond1 or sel_cond0
sel_close = (not USE_TRAILINGSTOP ? high >= sel_entry_price + sl : high >= sel_ts) or low<=sel_entry_price-tp//low<=last_traded_price - tp or high>=last_traded_price + sl //low <= ll or 

strategy.entry('buy', long=strategy.long, qty=trade_size, comment='buy', when=buy_entry)
strategy.close('buy', when=buy_close)
strategy.entry('sell', long=strategy.short, qty=trade_size, comment='sell', when=sel_entry)
strategy.close('sell', when=sel_close)