Chiến lược kênh hồi quy trung bình theo xu hướng


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

Chiến lược kênh hồi quy trung bình theo xu hướng

Tổng quan

Chiến lược này được thiết kế dựa trên chỉ số CCI một hệ thống giao dịch tự động theo dõi xu hướng linh hoạt. Nó có thể phát ra tín hiệu giao dịch trên hoặc xuống theo trục 0 của chỉ số CCI, hoặc có thể phát ra tín hiệu thông qua băng thông theo chiều lên xuống và băng thông theo chiều chéo tùy chỉnh. Chiến lược có thể thiết lập tỷ lệ dừng cố định, dừng lại, đồng thời có nhiều chức năng như giao dịch theo thời gian và giao dịch theo thời gian cố định hàng ngày.

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

  1. Sử dụng giao điểm 0 của chỉ số CCI để đánh giá xu hướng thị trường, CCI trên 0 là tín hiệu đi lên, CCI dưới 0 là tín hiệu đi xuống.

  2. Bằng cách tùy chỉnh CCI lên và xuống, khi CCI trên đeo vào băng thông là tín hiệu bullish, CCI dưới đeo vào băng thông là tín hiệu bearish. băng thông giao nhau là tín hiệu dừng lỗ.

  3. Có thể thiết lập chỉ giao dịch trong một khoảng thời gian nhất định, không giao dịch trong khoảng thời gian không giao dịch. Có thể thiết lập giao dịch trong khoảng thời gian cố định hàng ngày.

  4. Có thể thiết lập tỷ lệ dừng và dừng cố định.

  5. Thông báo Alert cho các giao dịch mở lỗ tùy chỉnh.

  6. Chiến lược hoàn toàn tùy chỉnh và linh hoạt, có thể điều chỉnh các chiến lược tối ưu hóa như tham số CCI, tham số băng thông, tham số dừng lỗ.

Phân tích lợi thế

  1. Sử dụng chỉ số CCI để đánh giá xu hướng thị trường, CCI nhạy cảm với sự thay đổi giá và có thể nhanh chóng nắm bắt các điểm biến động của thị trường.

  2. Đường băng tùy chỉnh có thể điều chỉnh theo các tham số của thị trường khác nhau, và đường băng cắt lỗ có thể kiểm soát rủi ro hiệu quả.

  3. Hỗ trợ nhiều thiết lập thời gian giao dịch, có thể điều chỉnh các tham số chiến lược theo các khoảng thời gian khác nhau, tận dụng các đặc điểm của các khoảng thời gian khác nhau để có được lợi nhuận vượt trội.

  4. Hỗ trợ cài đặt dừng lỗ cố định, có thể đặt trước tỷ lệ lợi nhuận và lỗ, kiểm soát hiệu quả rủi ro của các giao dịch cá nhân.

  5. Các tham số hoàn toàn có thể tùy chỉnh, có thể tối ưu hóa chiến lược cho các giống khác nhau và tình hình thị trường để có được hiệu quả tốt hơn.

Phân tích rủi ro

  1. Chỉ số CCI nhạy cảm với sự thay đổi giá, có thể tạo ra một số tín hiệu sai, nên được xác minh kết hợp với chỉ số chu kỳ dài hơn.

  2. Tỷ lệ dừng lỗ cố định không thể được điều chỉnh theo sự thay đổi của thị trường và nên được thiết lập theo tỷ lệ bảo vệ thích hợp.

  3. Thời gian giao dịch cố định có thể bỏ lỡ cơ hội điều chỉnh đường ngắn của thị trường, nên chọn khoảng thời gian có giá trị giao dịch thích hợp.

  4. Cần phải tối ưu hóa các tham số thường xuyên, nếu tối ưu hóa không đúng có thể dẫn đến giao dịch quá mức hoặc bỏ lỡ cơ hội giao dịch.

  5. Cần kết hợp các yếu tố khác nhau như tình hình ngành, môi trường vĩ mô, và không thể tránh hoàn toàn rủi ro chỉ bằng cách dựa vào tối ưu hóa tham số.

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

  1. Kiểm tra kết hợp với chỉ số chu kỳ dài và ngắn để tránh tín hiệu sai của CCI.

  2. Sử dụng các chỉ số như ATR để thiết lập dừng lỗ động.

  3. Kiểm tra hiệu quả của các tham số trong các khoảng thời gian khác nhau, chọn thời điểm giao dịch hiệu quả nhất.

  4. Tối ưu hóa tham số CCI, tham số băng thông, thích ứng với sự thay đổi của thị trường.

  5. Cân nhắc nhiều yếu tố như xu hướng, biến động và số lượng giao dịch.

  6. Chọn thời gian giao dịch phù hợp theo đặc điểm của loại giao dịch.

  7. Cân nhắc sử dụng thuật toán học máy để tự động tối ưu hóa chiến lược.

Tóm tắt

Chiến lược này nói chung là một hệ thống giao dịch theo dõi xu hướng rất linh hoạt và có thể tùy chỉnh. Chiến lược có nhiều lợi thế như sử dụng CCI để đánh giá xu hướng, kiểm soát rủi ro băng thông tùy chỉnh, thiết lập dừng lỗ cố định, chọn thời gian giao dịch. Ngoài ra, cũng cần lưu ý rằng CCI dễ tạo ra tín hiệu sai, tỷ lệ dừng lỗ cố định không thể điều chỉnh động.

Mã nguồn chiến lược
/*backtest
start: 2023-10-01 00:00:00
end: 2023-10-31 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/
// © REV0LUTI0N

//@version=4

strategy(title="CCI Strategy", overlay=true, initial_capital = 10000, default_qty_value = 10000, default_qty_type = strategy.cash)


//CCI Code

length = input(20, minval=1, title="CCI Length")
src = input(close, title="Source")
ma = sma(src, length)
cci = (src - ma) / (0.015 * dev(src, length))


// Strategy Backtesting
startDate  = input(timestamp("2099-10-01T00:00:00"), type = input.time, title='Backtesting Start Date')
finishDate = input(timestamp("9999-12-31T00:00:00"), type = input.time, title='Backtesting End Date')

time_cond  = true


//Time Restriction Settings
startendtime = input("", title='Time Frame To Enter Trades')
enableclose = input(false, title='Enable Close Trade At End Of Time Frame')
timetobuy = true
timetoclose = true


//Strategy Settings

//Strategy Settings - Enable Check Boxes
enableentry = input(true, title="Enter First Trade ASAP")
enableconfirmation = input(false, title="Wait For Cross To Enter First Trade")
enablezero =input(true, title="Use CCI Simple Cross Line For Entries & Exits")
enablebands = input(false, title="Use Upper & Lower Bands For Entries & Exits")

//Strategy Settings - Band Sources
ccisource = input(0, title="CCI Simple Cross")
upperbandsource =input(100, title="CCI Enter Long Band")
upperbandexitsource =input(100, title="CCI Exit Long Band")
lowerbandsource =input(-100, title="CCI Enter Short Band")
lowerbandexitsource =input(-100, title="CCI Exit Short Band")

//Strategy Settings - Crosses
simplecrossup = crossover(cci, ccisource)
simplecrossdown = crossunder(cci, ccisource)
uppercrossup = crossover(cci, upperbandsource)
lowercrossdown = crossunder(cci, lowerbandsource)
uppercrossdown = crossunder(cci, upperbandexitsource)
lowercrossup = crossover(cci, lowerbandexitsource)
upperstop = crossunder(cci, upperbandsource)
lowerstop = crossover(cci, lowerbandsource)


// Stop Loss & Take Profit % Based
enablesl = input(false, title='Enable Stop Loss')
enabletp = input(false, title='Enable Take Profit')
stopTick = input(5.0, title='Stop Loss %', type=input.float, step=0.1) / 100
takeTick = input(10.0, title='Take Profit %', type=input.float, step=0.1) / 100

longStop = strategy.position_avg_price * (1 - stopTick)
shortStop = strategy.position_avg_price * (1 + stopTick)
shortTake = strategy.position_avg_price * (1 - takeTick)
longTake = strategy.position_avg_price * (1 + takeTick)

plot(strategy.position_size > 0 and enablesl ? longStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Long Fixed SL")
plot(strategy.position_size < 0 and enablesl ? shortStop : na, style=plot.style_linebr, color=color.red, linewidth=1, title="Short Fixed SL")
plot(strategy.position_size > 0 and enabletp ? longTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Long Take Profit")
plot(strategy.position_size < 0 and enabletp ? shortTake : na, style=plot.style_linebr, color=color.green, linewidth=1, title="Short Take Profit")


// Alert messages
message_enterlong  = input("", title="Long Entry message")
message_entershort = input("", title="Short Entry message")
message_closelong = input("", title="Close Long message")
message_closeshort = input("", title="Close Short message")
    

//Strategy Execution

//Strategy Execution - Simple Line Cross
if (cci > ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (cci < ccisource and enablezero and enableentry and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

if (simplecrossup and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (simplecrossdown and enablezero and enableconfirmation and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Entry
if (uppercrossup and enablebands and time_cond and timetobuy)
    strategy.entry("Long", strategy.long, alert_message = message_enterlong)
if (lowercrossdown and enablebands and time_cond and timetobuy)
    strategy.entry("Short", strategy.short, alert_message = message_entershort)

//Strategy Execution - Upper and Lower Band Exit
if strategy.position_size > 0 and uppercrossdown and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowercrossup and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Upper and Lower Band Stops
if strategy.position_size > 0 and upperstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and lowerstop and enablebands and time_cond and timetobuy
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Close Trade At End Of Time Frame    
if strategy.position_size > 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closelong)
if strategy.position_size < 0 and timetoclose and enableclose and time_cond
    strategy.close_all(alert_message = message_closeshort)

//Strategy Execution - Stop Loss and Take Profit
if strategy.position_size > 0 and enablesl and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enablesl and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)
    
if strategy.position_size > 0 and enabletp and time_cond
    strategy.exit(id="Close Long", stop=longStop, limit=longTake, alert_message = message_closelong)
if strategy.position_size < 0 and enabletp and time_cond
    strategy.exit(id="Close Short", stop=shortStop, limit=shortTake, alert_message = message_closeshort)