Chiến lược động lực đảo ngược trung bình

Tác giả:ChaoZhang, Ngày: 2023-11-15 17:40:59
Tags:

img

Tổng quan

Chiến lược chuyển động đảo ngược trung bình là một chiến lược giao dịch xu hướng theo dõi mức giá trung bình ngắn hạn. Nó kết hợp chỉ số đảo ngược trung bình và chỉ số chuyển động để đánh giá xu hướng thị trường trung hạn.

Chiến lược logic

Chiến lược đầu tiên tính toán đường đảo ngược trung bình và độ lệch chuẩn của giá. Sau đó, kết hợp với các giá ngưỡng được đặt bởi các thông số Mức ngưỡng trên và Mức ngưỡng dưới, nó tính toán xem giá có vượt quá phạm vi một độ lệch chuẩn so với đường đảo ngược trung bình không. Nếu có, một tín hiệu giao dịch được tạo ra.

Đối với tín hiệu dài, giá cần phải nằm dưới đường đảo ngược trung bình bằng một độ lệch chuẩn, giá đóng là dưới SMA của khoảng thời gian LENGTH và trên SMA TREND, nếu ba điều kiện này được đáp ứng, một vị trí dài sẽ được mở. Điều kiện đóng là khi giá vượt qua SMA của khoảng thời gian LENGTH.

Đối với tín hiệu ngắn, giá cần phải nằm trên đường đảo ngược trung bình với một độ lệch chuẩn, giá đóng trên SMA của thời gian LENGTH và dưới SMA TREND, nếu ba điều kiện này được đáp ứng, một vị trí ngắn sẽ được mở. Điều kiện đóng là khi giá phá vỡ dưới SMA của thời gian LENGTH.

Chiến lược cũng kết hợp mục tiêu lợi nhuận phần trăm và phần trăm dừng lỗ để lấy lợi nhuận và quản lý dừng lỗ.

Phương pháp thoát có thể chọn giữa chéo trung bình động hoặc chéo hồi quy tuyến tính.

Thông qua sự kết hợp của giao dịch hai hướng, lọc xu hướng, lấy lợi nhuận và dừng lỗ, vv, nó nhận ra sự đánh giá và theo dõi xu hướng thị trường trung hạn.

Ưu điểm

  1. Chỉ số đảo ngược trung bình có thể đánh giá hiệu quả độ lệch của giá từ trung tâm giá trị.

  2. Chỉ số động lực SMA có thể lọc tiếng ồn thị trường ngắn hạn.

  3. Giao dịch hai hướng có thể nắm bắt đầy đủ các cơ hội xu hướng theo tất cả các hướng.

  4. Cơ chế lấy lợi nhuận và dừng lỗ có thể kiểm soát rủi ro hiệu quả.

  5. Các phương pháp xuất khẩu có thể được lựa chọn có thể linh hoạt để thích nghi với điều kiện thị trường.

  6. Một chiến lược giao dịch xu hướng hoàn chỉnh nắm bắt tốt hơn xu hướng trung hạn.

Rủi ro

  1. Chỉ số đảo ngược trung bình nhạy cảm với cài đặt tham số, cài đặt ngưỡng không chính xác có thể gây ra tín hiệu sai.

  2. Trong điều kiện thị trường biến động, dừng lỗ có thể được kích hoạt quá thường xuyên.

  3. Trong xu hướng bên, tần suất giao dịch có thể quá cao, làm tăng chi phí giao dịch và rủi ro trượt.

  4. Khi công cụ giao dịch không đủ thanh khoản, kiểm soát trượt có thể không tối ưu.

  5. Giao dịch hai hướng có rủi ro cao hơn, quản lý tiền bạc thận trọng là cần thiết.

Những rủi ro này có thể được kiểm soát thông qua tối ưu hóa tham số, điều chỉnh dừng lỗ, quản lý tiền vv.

Hướng dẫn tối ưu hóa

  1. Tối ưu hóa các thiết lập tham số của các chỉ số đảo ngược trung bình và động lượng để phù hợp hơn với các công cụ giao dịch khác nhau.

  2. Thêm các chỉ số xác định xu hướng để cải thiện khả năng nhận dạng xu hướng.

  3. Tối ưu hóa chiến lược dừng lỗ để thích nghi tốt hơn với biến động thị trường đáng kể.

  4. Thêm các mô-đun định kích thước vị trí để điều chỉnh kích thước vị trí dựa trên điều kiện thị trường.

  5. Thêm thêm các mô-đun quản lý rủi ro, chẳng hạn như kiểm soát rút vốn tối đa, kiểm soát đường cong vốn chủ sở hữu v.v.

  6. Xem xét kết hợp các phương pháp học máy để tự động tối ưu hóa các thông số chiến lược.

Tóm lại

Tóm lại, chiến lược động lực đảo ngược trung bình nắm bắt xu hướng đảo ngược trung bình dài hạn thông qua thiết kế chỉ số đơn giản và hiệu quả. Chiến lược có khả năng thích nghi và linh hoạt mạnh mẽ, nhưng cũng có một số rủi ro. Bằng cách tối ưu hóa liên tục và kết hợp với các chiến lược khác, có thể đạt được hiệu suất tốt hơn. Nhìn chung chiến lược khá hoàn chỉnh và là một phương pháp giao dịch xu hướng đáng xem xét.


/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1h
basePeriod: 15m
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/
// © GlobalMarketSignals

//@version=4
strategy("GMS: Mean Reversion Strategy", overlay=true)

LongShort       = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
Lookback        = input(title="Length", type=input.integer, defval=10, minval=0)
LThr1           = input(title="Upper threshold", type=input.float, defval=1, minval=0)
LThr            = input(title="Lower threshold", type=input.float, defval=-1, maxval=0)
src             = input(title="Source", type=input.source, defval=close)
LongShort2      = input(title="Linear Regression Exit or Moving Average Exit?", type=input.string, defval="MA", options=["LR", "MA"])
SMAlenL         = input(title="MA/LR Exit Length", type = input.integer ,defval=10)
SMALen2         = input(title="Trend SMA Length", type = input.integer ,defval=200)
AboveBelow      = input(title="Above or Below Trend SMA?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
PTbutton        = input(title="Profit Target On/Off", type=input.bool, defval=true)
ProfitTarget    = input(title="Profit Target %", type=input.float, defval=1, step=0.1, minval=0)
SLbutton        = input(title="Stop Loss On/Off", type=input.bool, defval=true)
StopLoss        = input(title="Stop Loss %", type=input.float, defval=-1, step=0.1, maxval=0)

x               = (src-linreg(src,Lookback,0))/(stdev(src,Lookback))

plot(linreg(src,Lookback,0))

//PROFIT TARGET & STOPLOSS

if PTbutton == true and SLbutton == true
    strategy.exit("EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick), loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
    if PTbutton == true and SLbutton == false
        strategy.exit("PT EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick))
    else
        if PTbutton == false and SLbutton == true
            strategy.exit("SL EXIT", loss=((close*(StopLoss*-0.01))/syminfo.mintick))
        else    
            strategy.cancel("PT EXIT")


////////////////////////
//MOVING AVERAGE EXIT//
//////////////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1  and close>sma(close,SMAlenL)  )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
    strategy.close("LONG", when = close>sma(close,SMAlenL))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<sma(close,SMAlenL))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
    strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) )
    strategy.close("SHORT", when = close<sma(close,SMAlenL))
    
/////////////////
//LIN REG EXIT//
///////////////

if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0)   and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1  and close>linreg(close,SMAlenL,0)  )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
    
//////

if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
    strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
    
///////    
    
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))

if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
    strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) )
    strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))






Thêm nữa