Chiến lược giao cắt đường trung bình động Momentum


Ngày tạo: 2023-09-21 21:29:22 sửa đổi lần cuối: 2023-09-21 21:29:22
sao chép: 1 Số nhấp chuột: 596
1
tập trung vào
1617
Người theo dõi

Tổng quan

Chiến lược này sử dụng các nguyên tắc giao thoa của các đường trung bình di chuyển nhanh và đường trung bình di chuyển chậm để đánh giá xu hướng thị trường để phát tín hiệu mua và bán. Chiến lược này đơn giản, dễ hiểu, dễ thực hiện và phù hợp với giao dịch đường ngắn trung bình.

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

Chiến lược này sử dụng hai đường trung bình di chuyển, một đường nhanh và một đường chậm. Các tham số đường nhanh là 3 ngày EMA và tham số đường chậm là 15 ngày EMA. Chiến lược đánh giá rằng khi đường nhanh vượt qua đường chậm từ phía dưới, thời điểm này được coi là đang có xu hướng tăng, và đó là một tín hiệu mua. Ngược lại, khi đường nhanh từ phía trên đi xuống và phá vỡ đường chậm, thời điểm này được coi là đang có xu hướng giảm, và đó là một tín hiệu bán.

Chiến lược cũng đặt một tham số nhanh hơn là EMA 3 ngày làm đường thoát nhanh. Khi giá giảm xuống đường thoát nhanh, nó sẽ xác định xu hướng đảo ngược và sẽ thoát khỏi vị trí đa đầu ban đầu. Tương tự, khi giá phá vỡ đường thoát một lần nữa, nó sẽ quay trở lại đà, do đó là tín hiệu cho việc nhập lại.

Cài đặt tín hiệu hoạt động cụ thể như sau:

  1. Đường nhanh từ dưới lên vượt qua đường chậm, làm nhiều hơn

  2. Dòng tốc độ nhanh từ trên xuống, phá vỡ dòng tốc độ chậm, tạo khoảng trống

  3. Giá giảm xuống đường thoát nhanh, giảm nhiều đơn

  4. Giá đã vượt qua đường thoát nhanh và làm thêm

Lợi thế chiến lược

  • Dễ sử dụng, chỉ cần cấu hình tốt hai moving average tham số, rất dễ thực hiện

  • Dữ liệu phản hồi đầy đủ, các chỉ số được sử dụng phổ biến hơn để đánh giá hiệu quả của chiến lược

  • Có nhiều tham số có thể cấu hình, bạn có thể tối ưu hóa chiến lược bằng cách điều chỉnh tham số

  • Kiểm soát rủi ro tốt hơn bằng cách thiết lập dừng lỗ nhanh

  • Các chiến lược của tôi rất rõ ràng, các tín hiệu của tôi rất rõ ràng.

  • Tần suất hoạt động vừa phải, tránh giao dịch quá thường xuyên

Rủi ro chiến lược

  • Là một chiến lược theo dõi xu hướng, nó tạo ra nhiều tín hiệu giả hơn khi xu hướng không rõ ràng

  • Đường trung bình di chuyển tự nó có tính chậm trễ và có thể bỏ lỡ điểm biến

  • Cài đặt tham số cố định không thể thích ứng với sự thay đổi của thị trường, nên được sử dụng để tối ưu hóa tham số

  • Cài đặt dừng lỗ có thể quá yếu và không thể dừng lỗ kịp thời

  • Các tín hiệu chiến lược thường xuyên và có thể có chi phí giao dịch cao hơn

  • Các tín hiệu giao dịch có thể bị lệch, nên được xác nhận kết hợp với các chỉ số khác

Có thể kiểm soát rủi ro bằng các phương pháp như tối ưu hóa tham số, xác nhận hỗ trợ bằng các chỉ số khác, nới lỏng tiêu chuẩn dừng lỗ thích hợp, cập nhật tham số kịp thời.

Tối ưu hóa chiến lược

  • Có thể kiểm tra các tham số trung bình di chuyển tối ưu hóa để phù hợp hơn với đặc điểm thị trường hiện tại

  • Có thể đưa ra nhiều chỉ số hơn để kết hợp thành một hệ thống chiến lược mạnh mẽ hơn

  • Có thể thiết lập các thiết lập tham số thích ứng, điều chỉnh tham số theo thị trường theo thời gian thực

  • Có thể giới thiệu các thuật toán học máy để tối ưu hóa chiến lược thông minh hơn

  • Có thể thiết lập động dừng, theo dõi dừng để kiểm soát rủi ro tốt hơn

  • Có thể kết hợp các chỉ số năng lượng, tránh bị lệch dẫn đến máy bị trượt

Tóm tắt

Chiến lược này nói chung là một chiến lược giao chéo đường trung bình di chuyển đôi đơn giản hơn. Nó sử dụng mối quan hệ giao chéo giữa đường trung bình nhanh và đường trung bình chậm để đánh giá xu hướng thị trường và thời gian mua bán. Ưu điểm của chiến lược là ý tưởng rõ ràng, dễ thực hiện, có thể thích ứng với các thị trường khác nhau thông qua tối ưu hóa tham số.

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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ehaarjee, ECHKAY, JackBauer007

//@version=4
//study(title="Tale_indicators", overlay=true)
strategy("Tale Indicators Strategy", overlay=true, precision=8, max_bars_back=200, pyramiding=0, initial_capital=20000, commission_type="percent", commission_value=0.1)

len_fast = input(3, minval=1, title="FAST EMA")
src_fast = input(close, title="Source for Fast")
fastMA = ema(src_fast, len_fast)
plot(fastMA, title="Slow EMA", color=color.orange)

len_slow = input(15, minval=1, title="SLOW EMA")
src_slow = input(close, title="Source for Slow")
slowMA = ema(src_slow, len_slow)
plot(slowMA, title="Fast EMA", color=color.blue)

len_fast_exit = input(3, minval=1, title="FAST EMA Exit")
src_fast_exit = input(close, title="Source for Fast Exit")
fastMAE = ema(src_fast_exit, len_fast_exit)
plot(fastMAE, title="Fast EMA Ex", color=color.red)


src_slow_enter_short = input(low, title="Source for Short Entry")
slowMASEn = ema(src_slow_enter_short, len_slow)

src_slow_enter_long = input(high, title="Source for Long Entry")
slowMALEn = ema(src_slow_enter_long, len_slow)

src_slow_exit_short = input(low, title="Source for Short Exit")
slowMASEx = ema(src_slow_enter_short, len_slow)

src_slow_exit_long = input(high, title="Source for Long Exit")
slowMALEx = ema(src_slow_enter_long, len_slow)

enter_long = crossover(fastMA, slowMALEn)
enter_short = crossunder(fastMA, slowMASEn)
exit_long = crossunder(fastMAE, slowMALEx)
exit_short = crossover(fastMAE, slowMALEx)

out_enter = iff(enter_long == true, 1, iff(enter_short == true, -1, 0))
plotarrow(out_enter, "Plot Enter Points", colorup=color.green, colordown=color.red, maxheight = 30)

bull = fastMA > slowMALEn
bear = fastMA < slowMASEn

c = bull ? color.green : bear ? color.red  : color.white
bgcolor(c)

exit_tuner = input(0.005, title="Exit Tuner to touch slowEMA")

bull_exit = (bull and (low>(fastMAE*(1+exit_tuner)))) or exit_long or (not(bear) and (fastMAE>high))
bear_exit = (bear and ((fastMAE*(1-exit_tuner))>high)) or exit_short or (not(bull) and (low>fastMAE))

bull_r = (bull and ((bull_exit[1]) or (bull_exit[2] and bull_exit[1])) and (low<=fastMAE))
bear_r = (bear and ((bear_exit[1]) or (bull_exit[2] and bull_exit[1])) and (fastMAE<=high))

bull_re = (bull and (low<slowMALEn)) and not(enter_long)
bear_re = (bear and (high>slowMASEn)) and not(enter_short)

bull_ree = (bull and ((low<slowMALEn) and not(bull_re[1] or enter_long[1]))) 
bear_ree = (bear and ((high>slowMASEn) and not(bear_re[1] or enter_short[1])))

bull_reenter =  (bull_r) and not(enter_long)
bear_reenter =  (bear_r) and not(enter_short)

plotshape(bull_exit, "Plot Bull Exit", style = shape.arrowdown, color=color.green, size=size.small, text="ExL", location=location.abovebar)
plotshape(bear_exit, "Plot Bear Exit", style = shape.arrowup, color=color.red, size=size.small, text="ExS", location=location.belowbar)

plotshape(bull_reenter, "Plot Bull ReEnter", style = shape.arrowup, color=color.green, size=size.small, text="ReL", location=location.belowbar)
plotshape(bear_reenter, "Plot Bear ReEnter", style = shape.arrowdown, color=color.red, size=size.small, text="ReS", location=location.abovebar)

run_strategy = input(true, title="Run Strategy")
// === INPUT BACKTEST RANGE ===
fromMonth = input(defval = 1,    title = "From Month",      type = input.integer, minval = 1, maxval = 12)
fromDay   = input(defval = 1,    title = "From Day",        type = input.integer, minval = 1, maxval = 31)
fromYear  = input(defval = 2020, title = "From Year",       type = input.integer, minval = 2000)
thruMonth = input(defval = 1,    title = "Thru Month",      type = input.integer, minval = 1, maxval = 12)
thruDay   = input(defval = 1,    title = "Thru Day",        type = input.integer, minval = 1, maxval = 31)
thruYear  = input(defval = 2100, title = "Thru Year",       type = input.integer, minval = 2000)

// === INPUT SHOW PLOT ===
showDate  = input(defval = true, title = "Show Date Range", type = input.bool)
// === FUNCTION EXAMPLE ===
start     = timestamp(fromYear, fromMonth, fromDay, 00, 00)        // backtest start window
finish    = timestamp(thruYear, thruMonth, thruDay, 23, 59)        // backtest finish window
window()  => true       // create function "within window of time"

var long_position_open = false
var short_position_open = false


if (enter_long and not(bull_exit) and not(long_position_open))
//    strategy.entry("LO", strategy.long, qty=4)
    long_position_open := true
    if (short_position_open)
//        strategy.close("SO")
        short_position_open := false

if (bull_reenter and not(long_position_open))  
//    strategy.entry("LO", strategy.long, qty=1)
    long_position_open := true

if (bull_exit and long_position_open)
//  strategy.close("LO")
    long_position_open := false
    
if (enter_short and not(bear_exit) and not(short_position_open))
//    strategy.entry("SO", strategy.short, qty=4)
    short_position_open := true
    if(long_position_open)
//        strategy.close("LO")
        long_position_open := false

if (bear_reenter and not(short_position_open))  
//    strategy.entry("SO", strategy.long, qty=1)
    long_position_open := true

if (bear_exit and short_position_open)
//    strategy.close("SO")
    short_position_open := false

if(run_strategy)
    strategy.entry("LO", strategy.long, when=(window() and enter_long), qty=4)
    strategy.entry("LO", strategy.long, when=(window() and bull_reenter and not(long_position_open)), qty=1)
    strategy.close("LO", when=(window() and bull_exit and long_position_open))
    strategy.entry("SO", strategy.short, when=(window() and enter_short), qty=4)
    strategy.entry("SO", strategy.short, when=(window() and bear_reenter and not(short_position_open)), qty=1)
    strategy.close("SO", when=(window() and bear_exit and short_position_open))