Chiến lược động lượng hồi quy trung bình


Ngày tạo: 2023-11-15 17:40:59 sửa đổi lần cuối: 2023-11-15 17:40:59
sao chép: 0 Số nhấp chuột: 833
1
tập trung vào
1617
Người theo dõi

Chiến lược động lượng hồi quy trung bình

Tổng quan

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

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

Chiến lược này đầu tiên tính toán đường trung bình và chênh lệch tiêu chuẩn của giá. Sau đó kết hợp các tham số Upper Threshold và Lower Threshold với các ngưỡng được thiết lập tốt, tính toán xem giá vượt quá đường trung bình và chênh lệch tiêu chuẩn. Nếu vượt quá, sẽ tạo ra tín hiệu giao dịch.

Đối với tín hiệu đa đầu, cần giá thấp hơn đường trung bình trở về một chênh lệch chuẩn, giá đóng cửa thấp hơn đường trung bình SMA của chu kỳ LENGTH và cao hơn đường trung bình TREND SMA, đáp ứng ba điều kiện này để mở một vị trí đa hướng. Điều kiện đặt hàng là đường trung bình SMA của chu kỳ LENGTH trên giá.

Đối với tín hiệu đầu trống, cần giá cao hơn đường trung bình trở về một chênh lệch chuẩn, giá đóng cửa cao hơn đường trung bình SMA của chu kỳ LENGTH và thấp hơn đường trung bình TREND SMA, đáp ứng ba điều kiện này để mở vị trí ở hướng làm trống. Điều kiện đặt hàng là đường trung bình SMA của chu kỳ LENGTH bên dưới giá.

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

Phương thức Exit có thể được lựa chọn là phá vỡ đường trung bình di chuyển hoặc phá vỡ đường hồi quy tuyến tính.

Thông qua nhiều giao dịch song phương, lọc xu hướng, dừng lỗ, và nhiều sự kết hợp khác nhau, việc đánh giá và theo dõi xu hướng trung hạn của thị trường được thực hiện.

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

  1. Chỉ số trung bình của giá trị trở lại có thể xác định hiệu quả liệu giá có lệch khỏi trung tâm giá trị hay không

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

  3. Nhiều giao dịch song phương, nắm bắt mọi cơ hội xu hướng

  4. Cơ chế dừng lỗ có thể kiểm soát rủi ro hiệu quả

  5. Lựa chọn Exit có thể thích ứng với môi trường thị trường

  6. Chiến lược giao dịch xu hướng đầy đủ, nắm bắt xu hướng trung hạn tốt hơn

Rủi ro chiến lược

  1. Chỉ số Mean Regression nhạy cảm với cài đặt tham số, cài đặt sai giá trị chuẩn có thể dẫn đến tín hiệu sai

  2. Có thể xảy ra thiệt hại quá thường xuyên trong một trận động đất lớn

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

  4. Kiểm soát điểm trượt có thể không phù hợp khi giao dịch với các loại có tính thanh khoản thấp

  5. Các giao dịch song phương trên không gian đa dạng có nhiều rủi ro và cần quản lý tài chính cẩn thận

Những rủi ro này có thể được kiểm soát bằng các phương pháp như tối ưu hóa tham số, điều chỉnh theo cách dừng lỗ và quản lý tài chính.

Hướng tối ưu hóa chiến lược

  1. Tối ưu hóa thiết lập tham số của chỉ số trung bình và động lực để phù hợp hơn với các đặc điểm của các giống khác nhau

  2. Tăng các chỉ số đánh giá xu hướng, nâng cao khả năng nhận diện xu hướng

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

  4. Thêm mô-đun quản lý vị trí, điều chỉnh quy mô vị trí theo điều kiện thị trường

  5. Thêm nhiều mô-đun điều khiển gió, như điều khiển rút lui tối đa, điều khiển đường cong ròng, v.v.

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

Tóm tắt

Nói tóm lại, chiến lược giá trị quay trở lại động lực thông qua thiết kế chỉ số đơn giản và hiệu quả, có thể nắm bắt xu hướng giá trị quay trở lại trong thời gian trung bình. Chiến lược có khả năng thích ứng mạnh mẽ và phổ biến, 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 các chiến lược khác, có thể đạt được hiệu suất tốt hơn.

Mã nguồn chiến lược
/*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))