Donchian Channel và Larry Williams Chiến lược chỉ số thương mại lớn

Tác giả:ChaoZhang, Ngày: 2024-04-12 17:27:25
Tags:

img

Tổng quan

Chiến lược này kết hợp ba chỉ số - Kênh Donchian, Chỉ số Thương mại lớn Larry Williams (LWTI) và Trung bình chuyển động khối lượng để tạo ra tín hiệu giao dịch. Nó đi vào vị trí dài khi giá vượt qua dải trên của Kênh Donchian, LWTI màu xanh lá cây và khối lượng lớn hơn so với đường trung bình chuyển động. Nó đi vào vị trí ngắn khi giá vượt qua dải dưới của Kênh Donchian, LWTI màu đỏ và khối lượng lớn hơn đường trung bình chuyển động. Chiến lược thoát khỏi vị trí khi giá đạt mức dừng lỗ hoặc lấy lợi nhuận, hoặc khi giá trở lại dải giữa của Kênh Donchian. Để ngăn chặn các mục nhập lặp đi lặp lại theo cùng một hướng xu hướng, chiến lược sử dụng một bộ đếm giao dịch chỉ cho phép các mục nhập mới sau khi giá vượt qua dải giữa của Kênh Donchian.

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

  1. Kênh Donchian: Một tín hiệu dài được tạo ra khi giá phá vỡ trên dải trên và một tín hiệu ngắn được tạo ra khi giá phá vỡ dưới dải dưới.
  2. Larry Williams Large Trade Index: Các vị trí dài chỉ được phép khi màu LWTI màu xanh lá cây, và các vị trí ngắn chỉ được phép khi màu đỏ.
  3. Khối lượng: Các mục chỉ được phép khi khối lượng hiện tại lớn hơn mức trung bình động khối lượng.
  4. Trade Counter: Để ngăn chặn các mục nhập lặp đi lặp lại theo cùng một hướng xu hướng, các mục nhập mới chỉ được phép sau khi giá vượt qua dải giữa của kênh Donchian.
  5. Stop Loss và Take Profit: Khi tham gia, khoảng cách dừng lỗ và lấy lợi nhuận được tính dựa trên ATR, với khoảng cách lấy lợi nhuận là khoảng cách dừng lỗ nhân tỷ lệ rủi ro-lợi nhuận.

Ưu điểm chiến lược

  1. Sự kết hợp của nhiều chỉ số để xác nhận tín hiệu giao dịch có thể lọc hiệu quả các tín hiệu sai và cải thiện chất lượng tín hiệu.
  2. Động thái dừng lỗ và lấy lợi nhuận - Điều chỉnh khoảng cách dừng lỗ và lấy lợi nhuận dựa trên sự biến động cho phép chiến lược thích nghi tốt hơn với những thay đổi của thị trường.
  3. Trình đếm giao dịch ngăn chặn các mục lặp lại trong cùng một xu hướng, kiểm soát tần suất giao dịch.
  4. Tỷ lệ rủi ro-lợi nhuận dựa trên lợi nhuận - Việc thiết lập mức lợi nhuận dựa trên tỷ lệ rủi ro-lợi nhuận được xác định trước cho phép lợi nhuận tiềm năng vượt quá rủi ro.

Rủi ro chiến lược

  1. Rủi ro tham số - Hiệu suất chiến lược bị ảnh hưởng đáng kể bởi các cài đặt tham số khác nhau, đòi hỏi tối ưu hóa dựa trên các đặc điểm và khung thời gian thị trường khác nhau.
  2. Rủi ro thị trường hỗn loạn - Trong điều kiện thị trường hỗn loạn, biến động thường xuyên có thể khiến chiến lược thường xuyên vào và ra khỏi các vị trí, dẫn đến hiệu suất kém.
  3. Rủi ro xu hướng - Nếu xu hướng thiếu sự bền vững, có thể xảy ra các bước vào và ra thường xuyên, dẫn đến tăng lỗ.
  4. Rủi ro thiên nga đen - Trong điều kiện thị trường cực đoan, các chỉ số có thể thất bại, dẫn đến hiệu suất chiến lược kém.

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

  1. Tối ưu hóa các tham số cho các thiết bị và khung thời gian khác nhau để tìm kết hợp tham số tốt nhất.
  2. Thêm các điều kiện lọc xu hướng, chẳng hạn như sử dụng các đường trung bình động hoặc chỉ số động lực, để chỉ nhập các vị trí khi xu hướng rõ ràng, giảm số lượng giao dịch trong môi trường hỗn loạn.
  3. Xem xét sử dụng các chiến lược phá vỡ phạm vi cho điều kiện thị trường hỗn loạn.
  4. Tối ưu hóa dừng lỗ và logic lợi nhuận bằng cách giới thiệu dừng lại hoặc các phương pháp khác.
  5. Đối với các điều kiện thị trường cực đoan, hãy xem xét việc đưa ra quản lý tiền cố định và giới hạn rút tiền tối đa.

Tóm lại

Chiến lược chỉ số thương mại lớn Donchian Channel và Larry Williams là một chiến lược thương mại theo xu hướng cổ điển. Nó nắm bắt hướng xu hướng bằng cách sử dụng kênh Donchian, lọc tín hiệu bằng cách sử dụng LWTI, khối lượng và các chỉ số khác, và sử dụng stop loss động và lấy lợi nhuận với kiểm soát rủi ro nghiêm ngặt. Nhìn chung, đây là một khuôn khổ chiến lược có tiềm năng lợi nhuận ổn định. Tuy nhiên, điều quan trọng cần lưu ý là chiến lược nhạy cảm với các thông số và hoạt động kém trong điều kiện thị trường hỗn loạn. Nó được khuyến cáo sử dụng trong các thị trường xu hướng. Trong ứng dụng thực tế, tối ưu hóa thêm các thông số và logic dựa trên các công cụ giao dịch và đặc điểm thị trường, cùng với quản lý tiền chặt chẽ, là cần thiết để đạt được lợi nhuận tốt và ổn định.


/*backtest
start: 2024-04-04 00:00:00
end: 2024-04-11 00:00:00
period: 1m
basePeriod: 1m
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/
// © DillonGrech
//
//This is a Donchian Channel Trading Strategy which was found through the 
//YouTube channel TradingLab. 
//
//This Strategy uses the Donchian Channel, Larry Williams Large Trade Index,
//and Volume with Moving Average indicators for long and short trades.
//
//Strategy will enter based off indicator entry conditions and will not
//re-enter a trade until the price crosses through the Donchian Channel
//basis line (to prevent re-entering trades in same trend). Strategy will
//exit at stop loss or take profit, or when price crosses donchian basis.
//
//The strategy has been coded by Dillon Grech as part of his YouTube channel
//and a detailed video can be found on his channel at:
//https://www.youtube.com/c/DillonGrech
//https://www.youtube.com/watch?v=5IFe2Vjf61Y
//Source code and template files can be found on his GitHub at:
//https://github.com/Dillon-Grech
//==============================================================================
//@version=5
strategy("Donchian Channel Strategy [DillonGrech]", overlay=true, margin_long=100, margin_short=100)

//==============================================================================
//DONCHIAN CHANNEL
//==============================================================================
//Allow user to select whether they would like to use indicator
Don_Input = input(true, title='Use Donchian Channel?', group = "Donchian Settings")

//Indicator
don_length = input.int(96, minval = 1, group = "Donchian Settings")
don_lower  = ta.lowest(don_length)
don_upper  = ta.highest(don_length)
don_basis  = math.avg(don_upper, don_lower)
plot(don_basis,     "Don Basis", color = #FF6D00)
u = plot(don_upper, "Don Upper", color = #2962FF)
l = plot(don_lower, "Don Lower", color = #2962FF)
fill(u, l, color = color.rgb(33, 150, 243, 95), title = "Background")

//Conditions - Enter trades when there is a cross of price and previous donchian channel value
Ind_1_L = Don_Input == false ? false : ta.crossover(close,don_upper[1])
Ind_1_S = Don_Input == false ? false : ta.crossunder(close,don_lower[1])

//==============================================================================
//LARRY WILLIAMS LARGE TRADE INDEX (LWTI) - LOXX
//==============================================================================
//Allow user to select whether they would like to use indicator
LWTI_Input = input(true, title='Use LWTI?', group = "LWTI Settings")

//Indicator
greencolor = #2DD204
redcolor = #D2042D 

variant(type, src, len) =>
    sig = 0.0
    if type == "SMA"
        sig := ta.sma(src, len) 
    else if type == "EMA"
        sig := ta.ema(src, len) 
    else if type == "WMA"
        sig := ta.wma(src, len)   
    else if type == "RMA"
        sig := ta.rma(src, len)  
    sig
    
LWTI_per = input.int(25, "Period", group = "LWTI Settings")
LWTI_smthit = input.bool(false, "Smooth LWPI?", group = "LWTI Settings")
LWTI_type = input.string("SMA", "Smoothing Type", options = ["EMA", "WMA", "RMA", "SMA"], group = "LWTI Settings")
LWTI_smthper = input.int(20, "Smoothing Period", group = "LWTI Settings")

LWTI_ma = ta.sma(close - nz(close[LWTI_per]), LWTI_per)
LWTI_atr = ta.atr(LWTI_per)
LWTI_out = LWTI_ma/LWTI_atr * 50 + 50
LWTI_out := LWTI_smthit ? variant(LWTI_type, LWTI_out, LWTI_smthper) : LWTI_out

LWTI_colorout = LWTI_out > 50 ? greencolor : redcolor

//Conditions - Enter on color of indicator
Ind_2_L = LWTI_Input == false ? true : LWTI_colorout == greencolor
Ind_2_S = LWTI_Input == false ? true : LWTI_colorout == redcolor

//==============================================================================
//VOLUME INDICATOR
//==============================================================================
//Allow user to select whether they would like to use indicator
Vol_Input = input(true, title='Use Volume?', group = "Volume Settings")

//Indicator
Vol_Ma_Period = input.int(30,"Volume MA Period", group = "Volume Settings")
Vol_Ma = ta.sma(volume,Vol_Ma_Period)

//Conditions - Enter when volume is greater than moving average
Ind_3_L = Vol_Input == false ? true : volume > Vol_Ma
Ind_3_S = Vol_Input == false ? true : volume > Vol_Ma

//==============================================================================
//DONCHIAN CHANNEL TRADE COUNTER
//==============================================================================
//Stores whether a trade has been taken, and resets when there is a cross of price and donchain basis
Trade_Counter = float(0)
Don_Basis_Cross = ta.cross(don_basis[1], close)
if strategy.position_size!=0
    Trade_Counter := 1
else if Don_Basis_Cross
    Trade_Counter := 0
else 
    Trade_Counter := Trade_Counter[1]

Plot_Trade_Counter = input.bool(false, "Plot Trade Position Counter?", group = "Plot Settings")
plotchar(Plot_Trade_Counter and Trade_Counter == 0 ? true : false, color = na, text = '0')
plotchar(Plot_Trade_Counter and Trade_Counter == 1 ? true : false, color = na, text = '1')

//==============================================================================
//ENTRY CONDITIONS
//==============================================================================
entry_long  = strategy.position_size<=0 and Ind_1_L and Ind_2_L and Ind_3_L and Trade_Counter[1] == 0
entry_short = strategy.position_size>=0 and Ind_1_S and Ind_2_S and Ind_3_S and Trade_Counter[1] == 0

if(entry_long)
    strategy.entry("Long Entry", strategy.long)
if(entry_short)
    strategy.entry("Short Entry", strategy.short)

//==============================================================================
// TAKE PROFIT AND STOP LOSS CONDITIONS
//==============================================================================
Stop_Input   = input(true, title='Use Stop Loss?', group = "Risk Settings")
Profit_Input = input(true, title='Use Take Profit?', group = "Risk Settings")
Profit_RR = input.float(2.0,"Risk Reward Profit Target", group = "Risk Settings")

//Store Price on new entry signal
Entry_Price = strategy.opentrades.entry_price(strategy.opentrades - 1)

//Store Donchain Channel Basis value on new entry signal
Entry_Don_Basis = float(0.0)
if strategy.position_size == 0 or entry_long or entry_short
    Entry_Don_Basis := don_basis
else
    Entry_Don_Basis := Entry_Don_Basis[1]

//Get stop loss distance
Stop_Distance = math.abs(Entry_Price - Entry_Don_Basis)*1.02

//For Long Trades, find the stop loss level
Stop_L = float(0.0)
if Stop_Input == true
    Stop_L := Entry_Price - Stop_Distance
else
    na

//For Long Trades, find the profit level
Profit_L = float(0.0)
if Profit_Input == true
    Profit_L := Entry_Price + Stop_Distance*Profit_RR
else
    na

//For Short Trades, find the stop loss level
Stop_S = float(0.0)
if Stop_Input == true
    Stop_S   := Entry_Price + Stop_Distance
else
    na

//For Short Trades, find the profit level
Profit_S = float(0.0)
if Profit_Input == true
    Profit_S := Entry_Price - Stop_Distance*Profit_RR
else
    na

//Plot profit and stop loss levels for long and short trades
plot(strategy.position_size > 0 ? Profit_L : na, color=color.lime, style=plot.style_linebr, linewidth=2)
plot(strategy.position_size > 0 ? Stop_L : na,   color=color.red,  style=plot.style_linebr, linewidth=2)
plot(strategy.position_size < 0 ? Profit_S : na, color=color.lime, style=plot.style_linebr, linewidth=2)
plot(strategy.position_size < 0 ? Stop_S : na,   color=color.red,  style=plot.style_linebr, linewidth=2)

//==============================================================================
//EXIT ORDERS
//==============================================================================
//Exit long trades
if Stop_Input
    strategy.exit(id = 'Exit Long', from_entry ='Long Entry', comment='Long Stop',  stop = Stop_L)

if Profit_Input
    strategy.exit(id = 'Exit Long', from_entry ='Long Entry', comment='Long Profit', limit = Profit_L)

//Exit short trades
if Stop_Input
    strategy.exit(id = 'Exit Short', from_entry ='Short Entry', comment='Short Stop', stop = Stop_S)

if Profit_Input
    strategy.exit(id = 'Exit Short', from_entry ='Short Entry', comment='Short Profit', limit = Profit_S)

//==============================================================================
//CLOSE ORDERS
//==============================================================================
exit_long  = close < don_basis
exit_short = close > don_basis

if(exit_long)
    strategy.close("Long Entry", comment='Long Close', qty_percent=100)
if(exit_short)
    strategy.close("Short Entry", comment='Short Close', qty_percent=100)

Thêm nữa