Chiến lược kênh đảo ngược trung bình CCI

Tác giả:ChaoZhang, Ngày: 2023-11-01 16:20:45
Tags:

img

Tổng quan

Chiến lược này được thiết kế như một hệ thống giao dịch theo xu hướng linh hoạt dựa trên chỉ số CCI. Nó có thể tạo ra các tín hiệu giao dịch dựa trên các đường chéo đường không CCI hoặc các đường chéo dải trên / dưới tùy chỉnh. Chiến lược cho phép thiết lập tỷ lệ dừng lỗ cố định và lấy lợi nhuận, giao dịch trong khung thời gian cụ thể và hơn thế nữa.

Chiến lược logic

  1. Sử dụng đường chéo CCI không để xác định xu hướng thị trường.

  2. Thiết lập các dải CCI trên và dưới tùy chỉnh. CCI vượt trên dải trên là tăng và vượt dưới dải dưới là giảm.

  3. Tùy chọn chỉ giao dịch trong khung thời gian cụ thể và đóng tất cả các vị trí bên ngoài các khoảng thời gian đó.

  4. Đặt mức dừng lỗ cố định và lấy tỷ lệ lợi nhuận.

  5. Thông báo cảnh báo tùy chỉnh cho tín hiệu vào và ra.

  6. Chiến lược có thể tùy chỉnh cao với các thông số CCI có thể điều chỉnh, băng tần, dừng, vv

Phân tích lợi thế

  1. CCI nhạy cảm với sự thay đổi giá, tốt để bắt được sự đảo ngược xu hướng.

  2. Các băng tần tùy chỉnh có thể được điều chỉnh cho các thị trường khác nhau.

  3. Hỗ trợ giao dịch trong các khung thời gian khác nhau với các thông số tối ưu dựa trên các đặc điểm.

  4. Các tỷ lệ rủi ro/lợi nhuận cố định và rủi ro giới hạn.

  5. Các thông số hoàn toàn tùy chỉnh tối ưu hóa chiến lược cho các sản phẩm và điều kiện thị trường khác nhau.

Phân tích rủi ro

  1. CCI dễ bị tín hiệu sai, nên xác minh các tín hiệu với các chỉ số khung thời gian dài hơn.

  2. Tỷ lệ phần trăm dừng / lấy cố định không thể thích nghi với các điều kiện thị trường thay đổi.

  3. Giao dịch trong khung thời gian cố định có nguy cơ mất cơ hội trong thời gian phạm vi.

  4. Việc tối ưu hóa các tham số thường xuyên có thể dẫn đến giao dịch quá mức hoặc thiếu giao dịch.

  5. Các yếu tố vĩ mô nên được xem xét, tối ưu hóa một mình không đủ để loại bỏ rủi ro.

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

  1. Thêm các chỉ số khung thời gian dài hơn để xác minh tín hiệu CCI.

  2. Tích hợp các điểm dừng / bắt động như ATR.

  3. Kiểm tra các thông số trong các khung thời gian khác nhau và tìm các khoảng thời gian hiệu quả cao.

  4. Tối ưu hóa các thông số và băng tần CCI cho thị trường thay đổi.

  5. Xem xét việc kết hợp các yếu tố khác như biến động và khối lượng.

  6. Chọn khung thời gian phù hợp với các sản phẩm giao dịch.

  7. Xem xét máy học để tự động hóa tối ưu hóa chiến lược.

Tóm lại

Nhìn chung, đây là một hệ thống theo dõi xu hướng rất linh hoạt và có thể tùy chỉnh. Những lợi thế chính là sử dụng CCI cho xu hướng, băng tần tùy chỉnh để hạn chế rủi ro, dừng / lấy cố định và lựa chọn khung thời gian. Cần phải theo dõi các tín hiệu CCI sai và dừng không linh hoạt. Những cải tiến trong tương lai có thể đến từ tối ưu hóa các thông số, lọc tín hiệu, chọn khung thời gian hiệu quả và kết hợp máy học để thích nghi tự động với những thay đổi trên thị trường, để đạt được lợi nhuận dư thừa nhất quán hơn.


/*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)



Thêm nữa